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

// Industry An industry that is being researched
//
// swagger:model Industry
type Industry struct {

	// The AccountIDs of the Companies in this Industry
	Companies []string `json:"Companies"`

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

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

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

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

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

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

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

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

	// The hierarchical level of this Industry
	Level *string `json:"Level,omitempty"`

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

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

	// The ID of the Parent Industry
	ParentIndustryID *string `json:"ParentIndustryID,omitempty"`

	// The full path of this industry, including Parent
	Path *string `json:"Path,omitempty"`

	// The list of Products in this industry
	Products []*Product `json:"Products"`

	// The CMS Slug for this Industry
	Slug *string `json:"Slug,omitempty"`

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

// Validate validates this industry
func (m *Industry) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

				return err
			}
		}

	}

	return nil
}

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

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

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

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

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

		if m.Products[i] != nil {

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

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

				return err
			}
		}

	}

	return nil
}

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

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