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

package models

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

import (
	"context"

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

// StatementStatementMetadata StatementMetadata contains metadata for the statement.
//
// swagger:model StatementStatementMetadata
type StatementStatementMetadata struct {

	// next_statement is the summary of the next month's statement.
	NextStatement *Billing20201105StatementOverview `json:"next_statement,omitempty"`

	// previous_statement is the summary of the previous month's statement.
	PreviousStatement *Billing20201105StatementOverview `json:"previous_statement,omitempty"`
}

// Validate validates this statement statement metadata
func (m *StatementStatementMetadata) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *StatementStatementMetadata) validateNextStatement(formats strfmt.Registry) error {
	if swag.IsZero(m.NextStatement) { // not required
		return nil
	}

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

	return nil
}

func (m *StatementStatementMetadata) validatePreviousStatement(formats strfmt.Registry) error {
	if swag.IsZero(m.PreviousStatement) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *StatementStatementMetadata) contextValidateNextStatement(ctx context.Context, formats strfmt.Registry) error {

	if m.NextStatement != nil {

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

		if err := m.NextStatement.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("next_statement")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("next_statement")
			}
			return err
		}
	}

	return nil
}

func (m *StatementStatementMetadata) contextValidatePreviousStatement(ctx context.Context, formats strfmt.Registry) error {

	if m.PreviousStatement != nil {

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

		if err := m.PreviousStatement.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("previous_statement")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("previous_statement")
			}
			return err
		}
	}

	return nil
}

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

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