// Code generated by go-swagger; DO NOT EDIT.

// All Code Copyright(c) 2018-2020 by Taxnexus, Inc.
// All rights reserved worldwide.
// Proprietary product; unlicensed use is not allowed

package vendor_gw_models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"strconv"

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

// PurchaseOrderBasic purchase order basic
//
// swagger:model PurchaseOrderBasic
type PurchaseOrderBasic struct {

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

	// Purchase Order Amount
	Amount float64 `json:"Amount,omitempty"`

	// Amount Due
	AmountDue float64 `json:"AmountDue,omitempty"`

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

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

	// items
	Items []*ItemBasic `json:"Items"`

	// Purcahse Order Date
	PODate string `json:"PODate,omitempty"`

	// Purchase Order Number
	PONumber string `json:"PONumber,omitempty"`

	// UUID Reference the master record that owns this item
	ParentFK string `json:"ParentFK,omitempty"`

	// Source System identifier for this record, if any
	Ref string `json:"Ref,omitempty"`

	// Sales Regulation Type
	SalesRegulation string `json:"SalesRegulation,omitempty"`

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

	// Subtotal
	Subtotal float64 `json:"Subtotal,omitempty"`

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

	// Unique Taxnexus ID
	UUID string `json:"UUID,omitempty"`
}

// Validate validates this purchase order basic
func (m *PurchaseOrderBasic) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *PurchaseOrderBasic) validateBusinessAddress(formats strfmt.Registry) error {

	if swag.IsZero(m.BusinessAddress) { // not required
		return nil
	}

	if m.BusinessAddress != nil {
		if err := m.BusinessAddress.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("BusinessAddress")
			}
			return err
		}
	}

	return nil
}

func (m *PurchaseOrderBasic) validateItems(formats strfmt.Registry) error {

	if swag.IsZero(m.Items) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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