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

package model

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

import (
	"context"
	"strconv"

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

// AgentTable agent table
//
// swagger:model agentTable
type AgentTable struct {

	// column_auto_gen represents column is auto_increment or auto_random
	ColumnAutoGen []bool `json:"column_auto_gen"`

	// column is pk
	ColumnIsPk []bool `json:"column_is_pk"`

	// row data types
	RowDataTypes []string `json:"row_data_types"`

	// row headers
	RowHeaders []string `json:"row_headers"`

	// row values
	RowValues []*AgentRow `json:"row_values"`

	// schema name
	SchemaName string `json:"schema_name,omitempty"`

	// table name
	TableName string `json:"table_name,omitempty"`
}

// Validate validates this agent table
func (m *AgentTable) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *AgentTable) validateRowValues(formats strfmt.Registry) error {
	if swag.IsZero(m.RowValues) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

func (m *AgentTable) contextValidateRowValues(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.RowValues); i++ {

		if m.RowValues[i] != nil {

			if swag.IsZero(m.RowValues[i]) { // not required
				return nil
			}

			if err := m.RowValues[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("row_values" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("row_values" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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