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

import (
	"context"
	stderrors "errors"

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

// Contract contract
//
// swagger:model Contract
type Contract struct {

	// Account
	AccountID *string `json:"AccountID,omitempty"`

	// Activated By
	ActivatedByID *string `json:"ActivatedByID,omitempty"`

	// Activated Date
	ActivatedDate *string `json:"ActivatedDate,omitempty"`

	// Billing Address
	BillingAddress *Address `json:"BillingAddress,omitempty"`

	// Billing Contact
	BillingContactID *string `json:"BillingContactID,omitempty"`

	// Company Signed Date
	CompanySignedDate *string `json:"CompanySignedDate,omitempty"`

	// Company Signed By
	CompanySignedID *string `json:"CompanySignedID,omitempty"`

	// Contract Number
	ContractNumber *string `json:"ContractNumber,omitempty"`

	// Contract Term (months)
	ContractTerm *float64 `json:"ContractTerm,omitempty"`

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

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

	// Customer Signed Date
	CustomerSignedDate *string `json:"CustomerSignedDate,omitempty"`

	// Customer Signed By
	CustomerSignedID *string `json:"CustomerSignedID,omitempty"`

	// Customer Signed Title
	CustomerSignedTitle *string `json:"CustomerSignedTitle,omitempty"`

	// End User
	DefaultEndUserID *string `json:"DefaultEndUserID,omitempty"`

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

	// Contract End Date
	EndDate *string `json:"EndDate,omitempty"`

	// End User
	EndUserID *string `json:"EndUserID,omitempty"`

	// Hourly Rate
	HourlyRate *float64 `json:"HourlyRate,omitempty"`

	// Telnexus 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"`

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

	// Payment Method
	PaymentMethodID *string `json:"PaymentMethodID,omitempty"`

	// Payment Terms
	PaymentTerms *string `json:"PaymentTerms,omitempty"`

	// Perpetual Agreement?
	Perpetual *bool `json:"Perpetual,omitempty"`

	// Shipping Address
	ShippingAddress *Address `json:"ShippingAddress,omitempty"`

	// Shipping Contact
	ShippingContactID *string `json:"ShippingContactID,omitempty"`

	// Contract Start Date
	StartDate *string `json:"StartDate,omitempty"`

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

	// Tenant Identifier
	TenantID *string `json:"TenantID,omitempty"`
}

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

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

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

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

func (m *Contract) validateBillingAddress(formats strfmt.Registry) error {
	if typeutils.IsZero(m.BillingAddress) { // not required
		return nil
	}

	if m.BillingAddress != nil {
		if err := m.BillingAddress.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("BillingAddress")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("BillingAddress")
			}

			return err
		}
	}

	return nil
}

func (m *Contract) validateShippingAddress(formats strfmt.Registry) error {
	if typeutils.IsZero(m.ShippingAddress) { // not required
		return nil
	}

	if m.ShippingAddress != nil {
		if err := m.ShippingAddress.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("ShippingAddress")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("ShippingAddress")
			}

			return err
		}
	}

	return nil
}

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

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

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

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

func (m *Contract) contextValidateBillingAddress(ctx context.Context, formats strfmt.Registry) error {

	if m.BillingAddress != nil {

		if typeutils.IsZero(m.BillingAddress) { // not required
			return nil
		}

		if err := m.BillingAddress.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("BillingAddress")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("BillingAddress")
			}

			return err
		}
	}

	return nil
}

func (m *Contract) contextValidateShippingAddress(ctx context.Context, formats strfmt.Registry) error {

	if m.ShippingAddress != nil {

		if typeutils.IsZero(m.ShippingAddress) { // not required
			return nil
		}

		if err := m.ShippingAddress.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("ShippingAddress")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("ShippingAddress")
			}

			return err
		}
	}

	return nil
}

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

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