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

// JournalEntry journal entry
//
// swagger:model JournalEntry
type JournalEntry struct {

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

	// Balanced?
	Balanced bool `json:"Balanced,omitempty"`

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

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

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

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

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

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

	// Rating Ingest ID
	IngestID string `json:"IngestID,omitempty"`

	// The Journal Items associated with this Journal Entry
	Items []*JournalItem `json:"Items"`

	// Journal Date
	JournalDate string `json:"JournalDate,omitempty"`

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

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

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

	// The ID of the period in which this Journal Entry occurs
	PeriodID string `json:"PeriodID,omitempty"`

	// Posted
	Posted bool `json:"Posted,omitempty"`

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

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

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

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

// Validate validates this journal entry
func (m *JournalEntry) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *JournalEntry) 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 *JournalEntry) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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