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

// Asset asset
//
// swagger:model asset
type Asset struct {

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

	// address
	Address *Address `json:"Address,omitempty"`

	// Asset Level
	AssetLevel *float64 `json:"AssetLevel,omitempty"`

	// Asset Provided By
	AssetProvidedByID *string `json:"AssetProvidedByID,omitempty"`

	// Asset Serviced By
	AssetServicedByID *string `json:"AssetServicedByID,omitempty"`

	// Company Product
	CompanyProductID *string `json:"CompanyProductID,omitempty"`

	// Consequence Of Failure
	ConsequenceOfFailure *string `json:"ConsequenceOfFailure,omitempty"`

	// Contact
	ContactID *string `json:"ContactID,omitempty"`

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

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

	// Current Amount
	CurrentAmount *float64 `json:"CurrentAmount,omitempty"`

	// Current Lifecycle End Date
	CurrentLifecycleEndDate *string `json:"CurrentLifecycleEndDate,omitempty"`

	// Current Lifecycle Start Date
	CurrentLifecycleStartDate *string `json:"CurrentLifecycleStartDate,omitempty"`

	// Current Monthly Recurring Revenue
	CurrentMrr *float64 `json:"CurrentMrr,omitempty"`

	// Current Quantity
	CurrentQuantity *float64 `json:"CurrentQuantity,omitempty"`

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

	// Digital Asset Status
	DigitalAssetStatus *string `json:"DigitalAssetStatus,omitempty"`

	// External Id
	ExternalIdentifier *string `json:"ExternalIdentifier,omitempty"`

	// Has Lifecycle Management
	HasLifecycleManagement *bool `json:"HasLifecycleManagement,omitempty"`

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

	// Install Date
	InstallDate *string `json:"InstallDate,omitempty"`

	// Competitor Asset
	IsCompetitorProduct *bool `json:"IsCompetitorProduct,omitempty"`

	// Internal Asset
	IsInternal *bool `json:"IsInternal,omitempty"`

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

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

	// Location
	LocationID *string `json:"LocationID,omitempty"`

	// MIME Type
	MIMEType *string `json:"MIMEType,omitempty"`

	// Manufacture Date
	ManufactureDate *string `json:"ManufactureDate,omitempty"`

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

	// Parent Asset
	ParentID *string `json:"ParentID,omitempty"`

	// Price
	Price *float64 `json:"Price,omitempty"`

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

	// Product Code
	ProductCode *string `json:"ProductCode,omitempty"`

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

	// Product Family
	ProductFamily *string `json:"ProductFamily,omitempty"`

	// Purchase Date
	PurchaseDate *string `json:"PurchaseDate,omitempty"`

	// Quantity
	Quantity *float64 `json:"Quantity,omitempty"`

	// Root Asset
	RootAssetID *string `json:"RootAssetID,omitempty"`

	// Serial Number
	SerialNumber *string `json:"SerialNumber,omitempty"`

	// Compatibility-only legacy field. The authoritative CRM Asset table does not persist Status; native CRM mutations reject non-null values.
	Status *string `json:"Status,omitempty"`

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

	// Product SKU
	StockKeepingUnit *string `json:"StockKeepingUnit,omitempty"`

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

	// Total Lifecycle Amount
	TotalLifecycleAmount *float64 `json:"TotalLifecycleAmount,omitempty"`

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

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

	// Usage End Date
	UsageEndDate *string `json:"UsageEndDate,omitempty"`
}

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

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

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

func (m *Asset) validateAddress(formats strfmt.Registry) error {
	if typeutils.IsZero(m.Address) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

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

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

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

func (m *Asset) contextValidateAddress(ctx context.Context, formats strfmt.Registry) error {

	if m.Address != nil {

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

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

			return err
		}
	}

	return nil
}

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

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