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

// CompanyProduct A software product or service vended by a Company
//
// swagger:model companyProduct
type CompanyProduct struct {

	// Account Email
	AccountEmail *string `json:"AccountEmail,omitempty"`

	// ID of the Company that owns this Product
	AccountID *string `json:"AccountID,omitempty"`

	// Account Logo
	AccountLogo *string `json:"AccountLogo,omitempty"`

	// Account Name
	AccountName *string `json:"AccountName,omitempty"`

	// Account Number
	AccountNumber *string `json:"AccountNumber,omitempty"`

	// Account Publish
	AccountPublish *bool `json:"AccountPublish,omitempty"`

	// Account Slug
	AccountSlug *string `json:"AccountSlug,omitempty"`

	// Account Website
	AccountWebsite *string `json:"AccountWebsite,omitempty"`

	// Salesforce AppExchange URL
	AppExchange *string `json:"AppExchange,omitempty"`

	// Created By User ID
	CreatedByID *string `json:"CreatedByID,omitempty"`

	// Created Date
	CreatedDate *string `json:"CreatedDate,omitempty"`

	// Description of product
	Description *string `json:"Description,omitempty"`

	// Enrichment Status
	EnrichmentStatus *string `json:"EnrichmentStatus,omitempty"`

	// Full Description of product
	FullDescription *string `json:"FullDescription,omitempty"`

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

	// Image Alt Text
	ImageAltText *string `json:"ImageAltText,omitempty"`

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

	// Industries
	Industries []*Industry `json:"Industries"`

	// Last Enriched By User ID
	LastEnrichedByID *string `json:"LastEnrichedByID,omitempty"`

	// Last Enriched Date
	LastEnrichmentDate *string `json:"LastEnrichmentDate,omitempty"`

	// Last Modified By User ID
	LastModifiedByID *string `json:"LastModifiedByID,omitempty"`

	// Last Modified Date
	LastModifiedDate *string `json:"LastModifiedDate,omitempty"`

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

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

	// Product Video ID
	ProductVideoID *string `json:"ProductVideoID,omitempty"`

	// Published
	Published *bool `json:"Published,omitempty"`

	// Salesforce Specific
	SalesforceSpecific *bool `json:"SalesforceSpecific,omitempty"`

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

	// TagLine
	TagLine *string `json:"TagLine,omitempty"`

	// Website
	URL *string `json:"URL,omitempty"`
}

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

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

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

func (m *CompanyProduct) validateIndustries(formats strfmt.Registry) error {
	if typeutils.IsZero(m.Industries) { // not required
		return nil
	}

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

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

				return err
			}
		}

	}

	return nil
}

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

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

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

func (m *CompanyProduct) contextValidateIndustries(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Industries[i] != nil {

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

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

				return err
			}
		}

	}

	return nil
}

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

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