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

// GlAccount gl account
//
// swagger:model GlAccount
type GlAccount struct {

	// Taxnexus Account that owns ths GL account
	AccountID string `json:"AccountID,omitempty"`

	// Account Level
	AccountLevel float64 `json:"AccountLevel,omitempty"`

	// Account Name
	AccountName string `json:"AccountName,omitempty"`

	// Account Sign
	AccountSign string `json:"AccountSign,omitempty"`

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

	// The GL Balances associated with this GL account
	Balances []*GlBalance `json:"Balances"`

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

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

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

	// Taxnexus Record Id Only; not used in POST
	ID string `json:"ID,omitempty"`

	// Is Active?
	IsActive bool `json:"IsActive,omitempty"`

	// Is Bank Account ?
	IsBankAccount bool `json:"IsBankAccount,omitempty"`

	// Is Summary?
	IsSummary bool `json:"IsSummary,omitempty"`

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

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

	// Display value for GL Account
	Name string `json:"Name,omitempty"`

	// Parent Foreign Key
	ParentFK string `json:"ParentFK,omitempty"`

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

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

	// Tenant that owns this object instance
	TenantID string `json:"TenantID,omitempty"`

	// Account Number
	AccountNumber float64 `json:"accountNumber,omitempty"`

	// Parent GL Account ID
	ParentGLAccountID string `json:"parentGLAccountID,omitempty"`
}

// Validate validates this gl account
func (m *GlAccount) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *GlAccount) validateBalances(formats strfmt.Registry) error {

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

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

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

	}

	return nil
}

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

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