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

// (c) 2012-2023 by Vernon Keenan
// All rights reserved worldwide.
// Proprietary product; unlicensed use is not allowed

package members_models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"
	"strconv"

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

// ResearchProject research project
//
// swagger:model researchProject
type ResearchProject struct {

	// account ID
	AccountID *string `json:"AccountID,omitempty"`

	// companies
	Companies []*ResearchProjectCompany `json:"Companies"`

	// created by ID
	CreatedByID *string `json:"CreatedByID,omitempty"`

	// created date
	CreatedDate *string `json:"CreatedDate,omitempty"`

	// description
	Description *string `json:"Description,omitempty"`

	// documents
	Documents []*ResearchProjectDocument `json:"Documents"`

	// ID
	ID string `json:"ID,omitempty"`

	// image alt text
	ImageAltText *string `json:"ImageAltText,omitempty"`

	// image URL
	ImageURL *string `json:"ImageURL,omitempty"`

	// last modified by ID
	LastModifiedByID *string `json:"LastModifiedByID,omitempty"`

	// last modified date
	LastModifiedDate *string `json:"LastModifiedDate,omitempty"`

	// logo
	Logo *string `json:"Logo,omitempty"`

	// name
	Name *string `json:"Name,omitempty"`

	// products
	Products []*ResearchProjectProduct `json:"Products"`

	// slug
	Slug *string `json:"Slug,omitempty"`

	// tenant ID
	TenantID *string `json:"TenantID,omitempty"`

	// topics
	Topics []*ResearchProjectTopic `json:"Topics"`

	// user ID
	UserID *string `json:"UserID,omitempty"`
}

// Validate validates this research project
func (m *ResearchProject) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *ResearchProject) validateCompanies(formats strfmt.Registry) error {
	if swag.IsZero(m.Companies) { // not required
		return nil
	}

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

		if m.Companies[i] != nil {
			if err := m.Companies[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("Companies" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("Companies" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *ResearchProject) validateDocuments(formats strfmt.Registry) error {
	if swag.IsZero(m.Documents) { // not required
		return nil
	}

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

		if m.Documents[i] != nil {
			if err := m.Documents[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("Documents" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("Documents" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *ResearchProject) validateProducts(formats strfmt.Registry) error {
	if swag.IsZero(m.Products) { // not required
		return nil
	}

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

		if m.Products[i] != nil {
			if err := m.Products[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("Products" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("Products" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *ResearchProject) validateTopics(formats strfmt.Registry) error {
	if swag.IsZero(m.Topics) { // not required
		return nil
	}

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

		if m.Topics[i] != nil {
			if err := m.Topics[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("Topics" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("Topics" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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

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

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

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

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

func (m *ResearchProject) contextValidateCompanies(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Companies[i] != nil {
			if err := m.Companies[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("Companies" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("Companies" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *ResearchProject) contextValidateDocuments(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Documents[i] != nil {
			if err := m.Documents[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("Documents" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("Documents" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *ResearchProject) contextValidateProducts(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Products[i] != nil {
			if err := m.Products[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("Products" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("Products" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *ResearchProject) contextValidateTopics(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Topics[i] != nil {
			if err := m.Topics[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("Topics" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("Topics" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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