/*
DM OpenAPI DOC

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

API version: 6.0.0
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package dm

import (
	"bytes"
	"encoding/json"
	"fmt"
)

// checks if the Task type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &Task{}

// Task task
type Task struct {
	BinlogFilterRule *map[string]TaskBinLogFilterRule `json:"binlog_filter_rule,omitempty"`
	// whether to enable support for the online ddl plugin
	EnhanceOnlineSchemaChange bool `json:"enhance_online_schema_change"`
	// ignore precheck items
	IgnoreCheckingItems []string `json:"ignore_checking_items,omitempty"`
	// downstream database for storing meta information
	MetaSchema *string `json:"meta_schema,omitempty"`
	// task name
	Name         string           `json:"name"`
	OnDuplicate  TaskOnDuplicate  `json:"on_duplicate"`
	ShardMode    *TaskShardMode   `json:"shard_mode,omitempty"`
	SourceConfig TaskSourceConfig `json:"source_config"`
	StatusList   []SubTaskStatus  `json:"status_list,omitempty"`
	// whether to enable strict optimistic shard mode
	StrictOptimisticShardMode *bool `json:"strict_optimistic_shard_mode,omitempty"`
	// table migrate rule
	TableMigrateRule []TaskTableMigrateRule `json:"table_migrate_rule"`
	TargetConfig     TaskTargetDataBase     `json:"target_config"`
	TaskMode         TaskTaskMode           `json:"task_mode"`
}

type _Task Task

// NewTask instantiates a new Task object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewTask(enhanceOnlineSchemaChange bool, name string, onDuplicate TaskOnDuplicate, sourceConfig TaskSourceConfig, tableMigrateRule []TaskTableMigrateRule, targetConfig TaskTargetDataBase, taskMode TaskTaskMode) *Task {
	this := Task{}
	this.EnhanceOnlineSchemaChange = enhanceOnlineSchemaChange
	var metaSchema string = "dm-meta"
	this.MetaSchema = &metaSchema
	this.Name = name
	this.OnDuplicate = onDuplicate
	this.SourceConfig = sourceConfig
	var strictOptimisticShardMode bool = false
	this.StrictOptimisticShardMode = &strictOptimisticShardMode
	this.TableMigrateRule = tableMigrateRule
	this.TargetConfig = targetConfig
	this.TaskMode = taskMode
	return &this
}

// NewTaskWithDefaults instantiates a new Task object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewTaskWithDefaults() *Task {
	this := Task{}
	var enhanceOnlineSchemaChange bool = true
	this.EnhanceOnlineSchemaChange = enhanceOnlineSchemaChange
	var metaSchema string = "dm-meta"
	this.MetaSchema = &metaSchema
	var strictOptimisticShardMode bool = false
	this.StrictOptimisticShardMode = &strictOptimisticShardMode
	return &this
}

// GetBinlogFilterRule returns the BinlogFilterRule field value if set, zero value otherwise.
func (o *Task) GetBinlogFilterRule() map[string]TaskBinLogFilterRule {
	if o == nil || IsNil(o.BinlogFilterRule) {
		var ret map[string]TaskBinLogFilterRule
		return ret
	}
	return *o.BinlogFilterRule
}

// GetBinlogFilterRuleOk returns a tuple with the BinlogFilterRule field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Task) GetBinlogFilterRuleOk() (*map[string]TaskBinLogFilterRule, bool) {
	if o == nil || IsNil(o.BinlogFilterRule) {
		return nil, false
	}
	return o.BinlogFilterRule, true
}

// HasBinlogFilterRule returns a boolean if a field has been set.
func (o *Task) HasBinlogFilterRule() bool {
	if o != nil && !IsNil(o.BinlogFilterRule) {
		return true
	}

	return false
}

// SetBinlogFilterRule gets a reference to the given map[string]TaskBinLogFilterRule and assigns it to the BinlogFilterRule field.
func (o *Task) SetBinlogFilterRule(v map[string]TaskBinLogFilterRule) {
	o.BinlogFilterRule = &v
}

// GetEnhanceOnlineSchemaChange returns the EnhanceOnlineSchemaChange field value
func (o *Task) GetEnhanceOnlineSchemaChange() bool {
	if o == nil {
		var ret bool
		return ret
	}

	return o.EnhanceOnlineSchemaChange
}

// GetEnhanceOnlineSchemaChangeOk returns a tuple with the EnhanceOnlineSchemaChange field value
// and a boolean to check if the value has been set.
func (o *Task) GetEnhanceOnlineSchemaChangeOk() (*bool, bool) {
	if o == nil {
		return nil, false
	}
	return &o.EnhanceOnlineSchemaChange, true
}

// SetEnhanceOnlineSchemaChange sets field value
func (o *Task) SetEnhanceOnlineSchemaChange(v bool) {
	o.EnhanceOnlineSchemaChange = v
}

// GetIgnoreCheckingItems returns the IgnoreCheckingItems field value if set, zero value otherwise.
func (o *Task) GetIgnoreCheckingItems() []string {
	if o == nil || IsNil(o.IgnoreCheckingItems) {
		var ret []string
		return ret
	}
	return o.IgnoreCheckingItems
}

// GetIgnoreCheckingItemsOk returns a tuple with the IgnoreCheckingItems field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Task) GetIgnoreCheckingItemsOk() ([]string, bool) {
	if o == nil || IsNil(o.IgnoreCheckingItems) {
		return nil, false
	}
	return o.IgnoreCheckingItems, true
}

// HasIgnoreCheckingItems returns a boolean if a field has been set.
func (o *Task) HasIgnoreCheckingItems() bool {
	if o != nil && !IsNil(o.IgnoreCheckingItems) {
		return true
	}

	return false
}

// SetIgnoreCheckingItems gets a reference to the given []string and assigns it to the IgnoreCheckingItems field.
func (o *Task) SetIgnoreCheckingItems(v []string) {
	o.IgnoreCheckingItems = v
}

// GetMetaSchema returns the MetaSchema field value if set, zero value otherwise.
func (o *Task) GetMetaSchema() string {
	if o == nil || IsNil(o.MetaSchema) {
		var ret string
		return ret
	}
	return *o.MetaSchema
}

// GetMetaSchemaOk returns a tuple with the MetaSchema field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Task) GetMetaSchemaOk() (*string, bool) {
	if o == nil || IsNil(o.MetaSchema) {
		return nil, false
	}
	return o.MetaSchema, true
}

// HasMetaSchema returns a boolean if a field has been set.
func (o *Task) HasMetaSchema() bool {
	if o != nil && !IsNil(o.MetaSchema) {
		return true
	}

	return false
}

// SetMetaSchema gets a reference to the given string and assigns it to the MetaSchema field.
func (o *Task) SetMetaSchema(v string) {
	o.MetaSchema = &v
}

// GetName returns the Name field value
func (o *Task) GetName() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Name
}

// GetNameOk returns a tuple with the Name field value
// and a boolean to check if the value has been set.
func (o *Task) GetNameOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Name, true
}

// SetName sets field value
func (o *Task) SetName(v string) {
	o.Name = v
}

// GetOnDuplicate returns the OnDuplicate field value
func (o *Task) GetOnDuplicate() TaskOnDuplicate {
	if o == nil {
		var ret TaskOnDuplicate
		return ret
	}

	return o.OnDuplicate
}

// GetOnDuplicateOk returns a tuple with the OnDuplicate field value
// and a boolean to check if the value has been set.
func (o *Task) GetOnDuplicateOk() (*TaskOnDuplicate, bool) {
	if o == nil {
		return nil, false
	}
	return &o.OnDuplicate, true
}

// SetOnDuplicate sets field value
func (o *Task) SetOnDuplicate(v TaskOnDuplicate) {
	o.OnDuplicate = v
}

// GetShardMode returns the ShardMode field value if set, zero value otherwise.
func (o *Task) GetShardMode() TaskShardMode {
	if o == nil || IsNil(o.ShardMode) {
		var ret TaskShardMode
		return ret
	}
	return *o.ShardMode
}

// GetShardModeOk returns a tuple with the ShardMode field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Task) GetShardModeOk() (*TaskShardMode, bool) {
	if o == nil || IsNil(o.ShardMode) {
		return nil, false
	}
	return o.ShardMode, true
}

// HasShardMode returns a boolean if a field has been set.
func (o *Task) HasShardMode() bool {
	if o != nil && !IsNil(o.ShardMode) {
		return true
	}

	return false
}

// SetShardMode gets a reference to the given TaskShardMode and assigns it to the ShardMode field.
func (o *Task) SetShardMode(v TaskShardMode) {
	o.ShardMode = &v
}

// GetSourceConfig returns the SourceConfig field value
func (o *Task) GetSourceConfig() TaskSourceConfig {
	if o == nil {
		var ret TaskSourceConfig
		return ret
	}

	return o.SourceConfig
}

// GetSourceConfigOk returns a tuple with the SourceConfig field value
// and a boolean to check if the value has been set.
func (o *Task) GetSourceConfigOk() (*TaskSourceConfig, bool) {
	if o == nil {
		return nil, false
	}
	return &o.SourceConfig, true
}

// SetSourceConfig sets field value
func (o *Task) SetSourceConfig(v TaskSourceConfig) {
	o.SourceConfig = v
}

// GetStatusList returns the StatusList field value if set, zero value otherwise.
func (o *Task) GetStatusList() []SubTaskStatus {
	if o == nil || IsNil(o.StatusList) {
		var ret []SubTaskStatus
		return ret
	}
	return o.StatusList
}

// GetStatusListOk returns a tuple with the StatusList field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Task) GetStatusListOk() ([]SubTaskStatus, bool) {
	if o == nil || IsNil(o.StatusList) {
		return nil, false
	}
	return o.StatusList, true
}

// HasStatusList returns a boolean if a field has been set.
func (o *Task) HasStatusList() bool {
	if o != nil && !IsNil(o.StatusList) {
		return true
	}

	return false
}

// SetStatusList gets a reference to the given []SubTaskStatus and assigns it to the StatusList field.
func (o *Task) SetStatusList(v []SubTaskStatus) {
	o.StatusList = v
}

// GetStrictOptimisticShardMode returns the StrictOptimisticShardMode field value if set, zero value otherwise.
func (o *Task) GetStrictOptimisticShardMode() bool {
	if o == nil || IsNil(o.StrictOptimisticShardMode) {
		var ret bool
		return ret
	}
	return *o.StrictOptimisticShardMode
}

// GetStrictOptimisticShardModeOk returns a tuple with the StrictOptimisticShardMode field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Task) GetStrictOptimisticShardModeOk() (*bool, bool) {
	if o == nil || IsNil(o.StrictOptimisticShardMode) {
		return nil, false
	}
	return o.StrictOptimisticShardMode, true
}

// HasStrictOptimisticShardMode returns a boolean if a field has been set.
func (o *Task) HasStrictOptimisticShardMode() bool {
	if o != nil && !IsNil(o.StrictOptimisticShardMode) {
		return true
	}

	return false
}

// SetStrictOptimisticShardMode gets a reference to the given bool and assigns it to the StrictOptimisticShardMode field.
func (o *Task) SetStrictOptimisticShardMode(v bool) {
	o.StrictOptimisticShardMode = &v
}

// GetTableMigrateRule returns the TableMigrateRule field value
func (o *Task) GetTableMigrateRule() []TaskTableMigrateRule {
	if o == nil {
		var ret []TaskTableMigrateRule
		return ret
	}

	return o.TableMigrateRule
}

// GetTableMigrateRuleOk returns a tuple with the TableMigrateRule field value
// and a boolean to check if the value has been set.
func (o *Task) GetTableMigrateRuleOk() ([]TaskTableMigrateRule, bool) {
	if o == nil {
		return nil, false
	}
	return o.TableMigrateRule, true
}

// SetTableMigrateRule sets field value
func (o *Task) SetTableMigrateRule(v []TaskTableMigrateRule) {
	o.TableMigrateRule = v
}

// GetTargetConfig returns the TargetConfig field value
func (o *Task) GetTargetConfig() TaskTargetDataBase {
	if o == nil {
		var ret TaskTargetDataBase
		return ret
	}

	return o.TargetConfig
}

// GetTargetConfigOk returns a tuple with the TargetConfig field value
// and a boolean to check if the value has been set.
func (o *Task) GetTargetConfigOk() (*TaskTargetDataBase, bool) {
	if o == nil {
		return nil, false
	}
	return &o.TargetConfig, true
}

// SetTargetConfig sets field value
func (o *Task) SetTargetConfig(v TaskTargetDataBase) {
	o.TargetConfig = v
}

// GetTaskMode returns the TaskMode field value
func (o *Task) GetTaskMode() TaskTaskMode {
	if o == nil {
		var ret TaskTaskMode
		return ret
	}

	return o.TaskMode
}

// GetTaskModeOk returns a tuple with the TaskMode field value
// and a boolean to check if the value has been set.
func (o *Task) GetTaskModeOk() (*TaskTaskMode, bool) {
	if o == nil {
		return nil, false
	}
	return &o.TaskMode, true
}

// SetTaskMode sets field value
func (o *Task) SetTaskMode(v TaskTaskMode) {
	o.TaskMode = v
}

func (o Task) MarshalJSON() ([]byte, error) {
	toSerialize, err := o.ToMap()
	if err != nil {
		return []byte{}, err
	}
	return json.Marshal(toSerialize)
}

func (o Task) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	if !IsNil(o.BinlogFilterRule) {
		toSerialize["binlog_filter_rule"] = o.BinlogFilterRule
	}
	toSerialize["enhance_online_schema_change"] = o.EnhanceOnlineSchemaChange
	if !IsNil(o.IgnoreCheckingItems) {
		toSerialize["ignore_checking_items"] = o.IgnoreCheckingItems
	}
	if !IsNil(o.MetaSchema) {
		toSerialize["meta_schema"] = o.MetaSchema
	}
	toSerialize["name"] = o.Name
	toSerialize["on_duplicate"] = o.OnDuplicate
	if !IsNil(o.ShardMode) {
		toSerialize["shard_mode"] = o.ShardMode
	}
	toSerialize["source_config"] = o.SourceConfig
	if !IsNil(o.StatusList) {
		toSerialize["status_list"] = o.StatusList
	}
	if !IsNil(o.StrictOptimisticShardMode) {
		toSerialize["strict_optimistic_shard_mode"] = o.StrictOptimisticShardMode
	}
	toSerialize["table_migrate_rule"] = o.TableMigrateRule
	toSerialize["target_config"] = o.TargetConfig
	toSerialize["task_mode"] = o.TaskMode
	return toSerialize, nil
}

func (o *Task) UnmarshalJSON(data []byte) (err error) {
	// This validates that all required properties are included in the JSON object
	// by unmarshalling the object into a generic map with string keys and checking
	// that every required field exists as a key in the generic map.
	requiredProperties := []string{
		"enhance_online_schema_change",
		"name",
		"on_duplicate",
		"source_config",
		"table_migrate_rule",
		"target_config",
		"task_mode",
	}

	allProperties := make(map[string]interface{})

	err = json.Unmarshal(data, &allProperties)

	if err != nil {
		return err
	}

	for _, requiredProperty := range requiredProperties {
		if _, exists := allProperties[requiredProperty]; !exists {
			return fmt.Errorf("no value given for required property %v", requiredProperty)
		}
	}

	varTask := _Task{}

	decoder := json.NewDecoder(bytes.NewReader(data))
	decoder.DisallowUnknownFields()
	err = decoder.Decode(&varTask)

	if err != nil {
		return err
	}

	*o = Task(varTask)

	return err
}

type NullableTask struct {
	value *Task
	isSet bool
}

func (v NullableTask) Get() *Task {
	return v.value
}

func (v *NullableTask) Set(val *Task) {
	v.value = val
	v.isSet = true
}

func (v NullableTask) IsSet() bool {
	return v.isSet
}

func (v *NullableTask) Unset() {
	v.value = nil
	v.isSet = false
}

func NewNullableTask(val *Task) *NullableTask {
	return &NullableTask{value: val, isSet: true}
}

func (v NullableTask) MarshalJSON() ([]byte, error) {
	return json.Marshal(v.value)
}

func (v *NullableTask) UnmarshalJSON(src []byte) error {
	v.isSet = true
	return json.Unmarshal(src, &v.value)
}
