// Code generated by go-swagger; DO NOT EDIT.

// (c) 2012-2020 by Taxnexus, Inc.
// All rights reserved worldwide.
// Proprietary product; unlicensed use is not allowed

package members_models

import (
	"context"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag/jsonutils"
	"github.com/go-openapi/swag/typeutils"
	"github.com/go-openapi/validate"
)

// TenantMembershipAuditFields tenant membership audit fields
//
// swagger:model TenantMembershipAuditFields
type TenantMembershipAuditFields struct {

	// created by Id
	// Read Only: true
	// Format: uuid
	CreatedByID *strfmt.UUID `json:"createdById,omitempty"`

	// Server-owned UTC creation timestamp.
	// Required: true
	// Format: date-time
	CreatedDate *strfmt.DateTime `json:"createdDate"`

	// Server-generated membership identifier.
	// Required: true
	// Format: uuid
	ID *strfmt.UUID `json:"id"`

	// last modified by Id
	// Read Only: true
	// Format: uuid
	LastModifiedByID *strfmt.UUID `json:"lastModifiedById,omitempty"`

	// Server-owned optimistic concurrency token.
	// Required: true
	// Format: date-time
	LastModifiedDate *strfmt.DateTime `json:"lastModifiedDate"`
}

// Validate validates this tenant membership audit fields
func (m *TenantMembershipAuditFields) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateCreatedByID(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateCreatedDate(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateID(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateLastModifiedByID(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateLastModifiedDate(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *TenantMembershipAuditFields) validateCreatedByID(formats strfmt.Registry) error {
	if typeutils.IsZero(m.CreatedByID) { // not required
		return nil
	}

	if err := validate.FormatOf("createdById", "body", "uuid", m.CreatedByID.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *TenantMembershipAuditFields) validateCreatedDate(formats strfmt.Registry) error {

	if err := validate.Required("createdDate", "body", m.CreatedDate); err != nil {
		return err
	}

	if err := validate.FormatOf("createdDate", "body", "date-time", m.CreatedDate.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *TenantMembershipAuditFields) validateID(formats strfmt.Registry) error {

	if err := validate.Required("id", "body", m.ID); err != nil {
		return err
	}

	if err := validate.FormatOf("id", "body", "uuid", m.ID.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *TenantMembershipAuditFields) validateLastModifiedByID(formats strfmt.Registry) error {
	if typeutils.IsZero(m.LastModifiedByID) { // not required
		return nil
	}

	if err := validate.FormatOf("lastModifiedById", "body", "uuid", m.LastModifiedByID.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *TenantMembershipAuditFields) validateLastModifiedDate(formats strfmt.Registry) error {

	if err := validate.Required("lastModifiedDate", "body", m.LastModifiedDate); err != nil {
		return err
	}

	if err := validate.FormatOf("lastModifiedDate", "body", "date-time", m.LastModifiedDate.String(), formats); err != nil {
		return err
	}

	return nil
}

// ContextValidate validate this tenant membership audit fields based on the context it is used
func (m *TenantMembershipAuditFields) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := m.contextValidateCreatedByID(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateLastModifiedByID(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *TenantMembershipAuditFields) contextValidateCreatedByID(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "createdById", "body", m.CreatedByID); err != nil {
		return err
	}

	return nil
}

func (m *TenantMembershipAuditFields) contextValidateLastModifiedByID(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "lastModifiedById", "body", m.LastModifiedByID); err != nil {
		return err
	}

	return nil
}

// MarshalBinary interface implementation
func (m *TenantMembershipAuditFields) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return jsonutils.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *TenantMembershipAuditFields) UnmarshalBinary(b []byte) error {
	var res TenantMembershipAuditFields
	if err := jsonutils.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
