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

// Topic A research topic that collects data
//
// swagger:model Topic
type Topic struct {

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

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

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

	// The list of Factors used to analyze this industry
	Factors []*Factor `json:"Factors"`

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

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

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

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

	// The ID of the Parent Topic
	ParentTopicID *string `json:"ParentTopicID,omitempty"`

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

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

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

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

func (m *Topic) validateFactors(formats strfmt.Registry) error {
	if swag.IsZero(m.Factors) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

func (m *Topic) contextValidateFactors(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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