// 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"
	"github.com/go-openapi/validate"
)

// DataflowImportCreateReq dataflow import create req
//
// swagger:model dataflowImportCreateReq
type DataflowImportCreateReq struct {

	// aws access key id
	AwsAccessKeyID string `json:"aws_access_key_id,omitempty"`

	// aws role arn
	AwsRoleArn string `json:"aws_role_arn,omitempty"`

	// aws secret access key
	AwsSecretAccessKey string `json:"aws_secret_access_key,omitempty"`

	// cluster id
	// Required: true
	ClusterID *string `json:"cluster_id"`

	// csv format
	CsvFormat *DataflowCustomCSVFormat `json:"csv_format,omitempty"`

	// 1: sql statement(dumpling default format
	// 2: aurora snapshot(parquet)
	// 3: custom csv
	// 4: parquet format(not aurora)
	// Required: true
	DataFormat *int64 `json:"data_format"`

	// 1: aws s3
	// 2: GCS
	// Required: true
	DataSourceType *int64 `json:"data_source_type"`

	// dup handling for sql
	DupHandlingForSQL *DataflowDupHandlingForSQL `json:"dup_handling_for_sql,omitempty"`

	// deprecated, use target_table_infos instead
	Filter string `json:"filter,omitempty"`

	// local import cfg
	LocalImportCfg *DataflowLocalImportCfg `json:"local_import_cfg,omitempty"`

	// name
	Name string `json:"name,omitempty"`

	// need_drop_tables is only used in tutorial
	NeedDropTables bool `json:"need_drop_tables,omitempty"`

	// deprecated, use target_table_infos instead
	ObjectNamePattern string `json:"object_name_pattern,omitempty"`

	// org id
	// Required: true
	OrgID *string `json:"org_id"`

	// project id
	// Required: true
	ProjectID *string `json:"project_id"`

	// region
	// Required: true
	Region *string `json:"region"`

	// import info
	SourceURL string `json:"source_url,omitempty"`

	// deprecated, use internal password instead
	TargetPassword string `json:"target_password,omitempty"`

	// target table infos
	TargetTableInfos []*DataflowImportTargetTableInfo `json:"target_table_infos"`

	// deprecated, use target_table_infos instead
	TargetTablePattern string `json:"target_table_pattern,omitempty"`

	// deprecated, use internal user instead
	TargetUsername string `json:"target_username,omitempty"`
}

// Validate validates this dataflow import create req
func (m *DataflowImportCreateReq) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

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

func (m *DataflowImportCreateReq) validateClusterID(formats strfmt.Registry) error {

	if err := validate.Required("cluster_id", "body", m.ClusterID); err != nil {
		return err
	}

	return nil
}

func (m *DataflowImportCreateReq) validateCsvFormat(formats strfmt.Registry) error {
	if swag.IsZero(m.CsvFormat) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowImportCreateReq) validateDataFormat(formats strfmt.Registry) error {

	if err := validate.Required("data_format", "body", m.DataFormat); err != nil {
		return err
	}

	return nil
}

func (m *DataflowImportCreateReq) validateDataSourceType(formats strfmt.Registry) error {

	if err := validate.Required("data_source_type", "body", m.DataSourceType); err != nil {
		return err
	}

	return nil
}

func (m *DataflowImportCreateReq) validateDupHandlingForSQL(formats strfmt.Registry) error {
	if swag.IsZero(m.DupHandlingForSQL) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowImportCreateReq) validateLocalImportCfg(formats strfmt.Registry) error {
	if swag.IsZero(m.LocalImportCfg) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowImportCreateReq) validateOrgID(formats strfmt.Registry) error {

	if err := validate.Required("org_id", "body", m.OrgID); err != nil {
		return err
	}

	return nil
}

func (m *DataflowImportCreateReq) validateProjectID(formats strfmt.Registry) error {

	if err := validate.Required("project_id", "body", m.ProjectID); err != nil {
		return err
	}

	return nil
}

func (m *DataflowImportCreateReq) validateRegion(formats strfmt.Registry) error {

	if err := validate.Required("region", "body", m.Region); err != nil {
		return err
	}

	return nil
}

func (m *DataflowImportCreateReq) validateTargetTableInfos(formats strfmt.Registry) error {
	if swag.IsZero(m.TargetTableInfos) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

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

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

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

func (m *DataflowImportCreateReq) contextValidateCsvFormat(ctx context.Context, formats strfmt.Registry) error {

	if m.CsvFormat != nil {

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

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

	return nil
}

func (m *DataflowImportCreateReq) contextValidateDupHandlingForSQL(ctx context.Context, formats strfmt.Registry) error {

	if m.DupHandlingForSQL != nil {

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

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

	return nil
}

func (m *DataflowImportCreateReq) contextValidateLocalImportCfg(ctx context.Context, formats strfmt.Registry) error {

	if m.LocalImportCfg != nil {

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

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

	return nil
}

func (m *DataflowImportCreateReq) contextValidateTargetTableInfos(ctx context.Context, formats strfmt.Registry) error {

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

		if m.TargetTableInfos[i] != nil {

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

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

	}

	return nil
}

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

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