/*
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 OperateTaskTableStructureRequest type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &OperateTaskTableStructureRequest{}

// OperateTaskTableStructureRequest action to operate table request
type OperateTaskTableStructureRequest struct {
	// Writes the schema to the checkpoint so that DM can load it after restarting the task
	Flush *bool `json:"flush,omitempty"`
	// sql you want to operate
	SqlContent string `json:"sql_content"`
	// Updates the optimistic sharding metadata with this schema only used when an error occurs in the optimistic sharding DDL mode
	Sync *bool `json:"sync,omitempty"`
}

type _OperateTaskTableStructureRequest OperateTaskTableStructureRequest

// NewOperateTaskTableStructureRequest instantiates a new OperateTaskTableStructureRequest 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 NewOperateTaskTableStructureRequest(sqlContent string) *OperateTaskTableStructureRequest {
	this := OperateTaskTableStructureRequest{}
	var flush bool = true
	this.Flush = &flush
	this.SqlContent = sqlContent
	return &this
}

// NewOperateTaskTableStructureRequestWithDefaults instantiates a new OperateTaskTableStructureRequest 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 NewOperateTaskTableStructureRequestWithDefaults() *OperateTaskTableStructureRequest {
	this := OperateTaskTableStructureRequest{}
	var flush bool = true
	this.Flush = &flush
	return &this
}

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

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

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

	return false
}

// SetFlush gets a reference to the given bool and assigns it to the Flush field.
func (o *OperateTaskTableStructureRequest) SetFlush(v bool) {
	o.Flush = &v
}

// GetSqlContent returns the SqlContent field value
func (o *OperateTaskTableStructureRequest) GetSqlContent() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.SqlContent
}

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

// SetSqlContent sets field value
func (o *OperateTaskTableStructureRequest) SetSqlContent(v string) {
	o.SqlContent = v
}

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

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

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

	return false
}

// SetSync gets a reference to the given bool and assigns it to the Sync field.
func (o *OperateTaskTableStructureRequest) SetSync(v bool) {
	o.Sync = &v
}

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

func (o OperateTaskTableStructureRequest) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	if !IsNil(o.Flush) {
		toSerialize["flush"] = o.Flush
	}
	toSerialize["sql_content"] = o.SqlContent
	if !IsNil(o.Sync) {
		toSerialize["sync"] = o.Sync
	}
	return toSerialize, nil
}

func (o *OperateTaskTableStructureRequest) 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{
		"sql_content",
	}

	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)
		}
	}

	varOperateTaskTableStructureRequest := _OperateTaskTableStructureRequest{}

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

	if err != nil {
		return err
	}

	*o = OperateTaskTableStructureRequest(varOperateTaskTableStructureRequest)

	return err
}

type NullableOperateTaskTableStructureRequest struct {
	value *OperateTaskTableStructureRequest
	isSet bool
}

func (v NullableOperateTaskTableStructureRequest) Get() *OperateTaskTableStructureRequest {
	return v.value
}

func (v *NullableOperateTaskTableStructureRequest) Set(val *OperateTaskTableStructureRequest) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableOperateTaskTableStructureRequest(val *OperateTaskTableStructureRequest) *NullableOperateTaskTableStructureRequest {
	return &NullableOperateTaskTableStructureRequest{value: val, isSet: true}
}

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

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