// 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 research_models

import (
	"context"
	"encoding/json"
	stderrors "errors"
	"strconv"

	"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"
)

// CompanyProductProposal Server-owned draft proposal; it does not imply approval or authoritative publication
//
// swagger:model CompanyProductProposal
type CompanyProductProposal struct {

	// base version
	// Required: true
	// Format: date-time
	BaseVersion *strfmt.DateTime `json:"BaseVersion"`

	// client principal key
	// Required: true
	ClientPrincipalKey *string `json:"ClientPrincipalKey"`

	// company product ID
	// Required: true
	// Format: uuid
	CompanyProductID *strfmt.UUID `json:"CompanyProductID"`

	// company product name
	CompanyProductName *string `json:"CompanyProductName,omitempty"`

	// created date
	// Required: true
	// Format: date-time
	CreatedDate *strfmt.DateTime `json:"CreatedDate"`

	// fields
	// Required: true
	Fields []*CompanyProductProposalField `json:"Fields"`

	// ID
	// Required: true
	// Format: uuid
	ID *strfmt.UUID `json:"ID"`

	// last modified date
	// Required: true
	// Format: date-time
	LastModifiedDate *strfmt.DateTime `json:"LastModifiedDate"`

	// operation
	// Required: true
	// Enum: ["update"]
	Operation *string `json:"Operation"`

	// proposed by ID
	// Required: true
	// Format: uuid
	ProposedByID *strfmt.UUID `json:"ProposedByID"`

	// review reason
	// Max Length: 1000
	ReviewReason *string `json:"ReviewReason,omitempty"`

	// reviewed at
	// Format: date-time
	ReviewedAt *strfmt.DateTime `json:"ReviewedAt,omitempty"`

	// reviewed by ID
	// Format: uuid
	ReviewedByID *strfmt.UUID `json:"ReviewedByID,omitempty"`

	// status
	// Required: true
	// Enum: ["draft","submitted","approved","rejected"]
	Status *string `json:"Status"`

	// submitted at
	// Format: date-time
	SubmittedAt *strfmt.DateTime `json:"SubmittedAt,omitempty"`

	// tenant ID
	// Required: true
	// Format: uuid
	TenantID *strfmt.UUID `json:"TenantID"`
}

// Validate validates this company product proposal
func (m *CompanyProductProposal) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (m *CompanyProductProposal) validateBaseVersion(formats strfmt.Registry) error {

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

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

	return nil
}

func (m *CompanyProductProposal) validateClientPrincipalKey(formats strfmt.Registry) error {

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

	return nil
}

func (m *CompanyProductProposal) validateCompanyProductID(formats strfmt.Registry) error {

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

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

	return nil
}

func (m *CompanyProductProposal) 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 *CompanyProductProposal) validateFields(formats strfmt.Registry) error {

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

	for i := 0; i < len(m.Fields); i++ {
		if typeutils.IsZero(m.Fields[i]) { // not required
			continue
		}

		if m.Fields[i] != nil {
			if err := m.Fields[i].Validate(formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("Fields" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("Fields" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

func (m *CompanyProductProposal) 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 *CompanyProductProposal) 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
}

var companyProductProposalTypeOperationPropEnum []any

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["update"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		companyProductProposalTypeOperationPropEnum = append(companyProductProposalTypeOperationPropEnum, v)
	}
}

const (

	// CompanyProductProposalOperationUpdate captures enum value "update"
	CompanyProductProposalOperationUpdate string = "update"
)

// prop value enum
func (m *CompanyProductProposal) validateOperationEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, companyProductProposalTypeOperationPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (m *CompanyProductProposal) validateOperation(formats strfmt.Registry) error {

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

	// value enum
	if err := m.validateOperationEnum("Operation", "body", *m.Operation); err != nil {
		return err
	}

	return nil
}

func (m *CompanyProductProposal) validateProposedByID(formats strfmt.Registry) error {

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

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

	return nil
}

func (m *CompanyProductProposal) validateReviewReason(formats strfmt.Registry) error {
	if typeutils.IsZero(m.ReviewReason) { // not required
		return nil
	}

	if err := validate.MaxLength("ReviewReason", "body", *m.ReviewReason, 1000); err != nil {
		return err
	}

	return nil
}

func (m *CompanyProductProposal) validateReviewedAt(formats strfmt.Registry) error {
	if typeutils.IsZero(m.ReviewedAt) { // not required
		return nil
	}

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

	return nil
}

func (m *CompanyProductProposal) validateReviewedByID(formats strfmt.Registry) error {
	if typeutils.IsZero(m.ReviewedByID) { // not required
		return nil
	}

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

	return nil
}

var companyProductProposalTypeStatusPropEnum []any

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["draft","submitted","approved","rejected"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		companyProductProposalTypeStatusPropEnum = append(companyProductProposalTypeStatusPropEnum, v)
	}
}

const (

	// CompanyProductProposalStatusDraft captures enum value "draft"
	CompanyProductProposalStatusDraft string = "draft"

	// CompanyProductProposalStatusSubmitted captures enum value "submitted"
	CompanyProductProposalStatusSubmitted string = "submitted"

	// CompanyProductProposalStatusApproved captures enum value "approved"
	CompanyProductProposalStatusApproved string = "approved"

	// CompanyProductProposalStatusRejected captures enum value "rejected"
	CompanyProductProposalStatusRejected string = "rejected"
)

// prop value enum
func (m *CompanyProductProposal) validateStatusEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, companyProductProposalTypeStatusPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (m *CompanyProductProposal) validateStatus(formats strfmt.Registry) error {

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

	// value enum
	if err := m.validateStatusEnum("Status", "body", *m.Status); err != nil {
		return err
	}

	return nil
}

func (m *CompanyProductProposal) validateSubmittedAt(formats strfmt.Registry) error {
	if typeutils.IsZero(m.SubmittedAt) { // not required
		return nil
	}

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

	return nil
}

func (m *CompanyProductProposal) validateTenantID(formats strfmt.Registry) error {

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

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

	return nil
}

// ContextValidate validate this company product proposal based on the context it is used
func (m *CompanyProductProposal) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *CompanyProductProposal) contextValidateFields(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Fields); i++ {

		if m.Fields[i] != nil {

			if typeutils.IsZero(m.Fields[i]) { // not required
				return nil
			}

			if err := m.Fields[i].ContextValidate(ctx, formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("Fields" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("Fields" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

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

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