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

// DataflowLocalImportCfg dataflow local import cfg
//
// swagger:model dataflowLocalImportCfg
type DataflowLocalImportCfg struct {

	// do not create target table when columns.length is 0
	Columns []*DataflowColumnInfo `json:"columns"`

	// file name
	FileName string `json:"file_name,omitempty"`

	// original file name
	OriginalFileName string `json:"original_file_name,omitempty"`

	// pk columns
	PkColumns []string `json:"pk_columns"`

	// target table
	TargetTable *CommonTable `json:"target_table,omitempty"`

	// total size
	TotalSize int64 `json:"total_size,omitempty"`
}

// Validate validates this dataflow local import cfg
func (m *DataflowLocalImportCfg) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *DataflowLocalImportCfg) validateColumns(formats strfmt.Registry) error {
	if swag.IsZero(m.Columns) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *DataflowLocalImportCfg) validateTargetTable(formats strfmt.Registry) error {
	if swag.IsZero(m.TargetTable) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this dataflow local import cfg based on the context it is used
func (m *DataflowLocalImportCfg) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *DataflowLocalImportCfg) contextValidateColumns(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Columns[i] != nil {

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

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

	}

	return nil
}

func (m *DataflowLocalImportCfg) contextValidateTargetTable(ctx context.Context, formats strfmt.Registry) error {

	if m.TargetTable != nil {

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

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

	return nil
}

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

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