// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.

package datadogV2

import (
	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
)

// WorkflowDataRelationships The definition of `WorkflowDataRelationships` object.
type WorkflowDataRelationships struct {
	// The definition of `WorkflowUserRelationship` object.
	Creator *WorkflowUserRelationship `json:"creator,omitempty"`
	// The definition of `WorkflowUserRelationship` object.
	Owner *WorkflowUserRelationship `json:"owner,omitempty"`
	// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
	UnparsedObject       map[string]interface{} `json:"-"`
	AdditionalProperties map[string]interface{} `json:"-"`
}

// NewWorkflowDataRelationships instantiates a new WorkflowDataRelationships 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 NewWorkflowDataRelationships() *WorkflowDataRelationships {
	this := WorkflowDataRelationships{}
	return &this
}

// NewWorkflowDataRelationshipsWithDefaults instantiates a new WorkflowDataRelationships 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 NewWorkflowDataRelationshipsWithDefaults() *WorkflowDataRelationships {
	this := WorkflowDataRelationships{}
	return &this
}

// GetCreator returns the Creator field value if set, zero value otherwise.
func (o *WorkflowDataRelationships) GetCreator() WorkflowUserRelationship {
	if o == nil || o.Creator == nil {
		var ret WorkflowUserRelationship
		return ret
	}
	return *o.Creator
}

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

// HasCreator returns a boolean if a field has been set.
func (o *WorkflowDataRelationships) HasCreator() bool {
	return o != nil && o.Creator != nil
}

// SetCreator gets a reference to the given WorkflowUserRelationship and assigns it to the Creator field.
func (o *WorkflowDataRelationships) SetCreator(v WorkflowUserRelationship) {
	o.Creator = &v
}

// GetOwner returns the Owner field value if set, zero value otherwise.
func (o *WorkflowDataRelationships) GetOwner() WorkflowUserRelationship {
	if o == nil || o.Owner == nil {
		var ret WorkflowUserRelationship
		return ret
	}
	return *o.Owner
}

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

// HasOwner returns a boolean if a field has been set.
func (o *WorkflowDataRelationships) HasOwner() bool {
	return o != nil && o.Owner != nil
}

// SetOwner gets a reference to the given WorkflowUserRelationship and assigns it to the Owner field.
func (o *WorkflowDataRelationships) SetOwner(v WorkflowUserRelationship) {
	o.Owner = &v
}

// MarshalJSON serializes the struct using spec logic.
func (o WorkflowDataRelationships) MarshalJSON() ([]byte, error) {
	toSerialize := map[string]interface{}{}
	if o.UnparsedObject != nil {
		return datadog.Marshal(o.UnparsedObject)
	}
	if o.Creator != nil {
		toSerialize["creator"] = o.Creator
	}
	if o.Owner != nil {
		toSerialize["owner"] = o.Owner
	}

	for key, value := range o.AdditionalProperties {
		toSerialize[key] = value
	}
	return datadog.Marshal(toSerialize)
}

// UnmarshalJSON deserializes the given payload.
func (o *WorkflowDataRelationships) UnmarshalJSON(bytes []byte) (err error) {
	all := struct {
		Creator *WorkflowUserRelationship `json:"creator,omitempty"`
		Owner   *WorkflowUserRelationship `json:"owner,omitempty"`
	}{}
	if err = datadog.Unmarshal(bytes, &all); err != nil {
		return datadog.Unmarshal(bytes, &o.UnparsedObject)
	}
	additionalProperties := make(map[string]interface{})
	if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
		datadog.DeleteKeys(additionalProperties, &[]string{"creator", "owner"})
	} else {
		return err
	}

	hasInvalidField := false
	if all.Creator != nil && all.Creator.UnparsedObject != nil && o.UnparsedObject == nil {
		hasInvalidField = true
	}
	o.Creator = all.Creator
	if all.Owner != nil && all.Owner.UnparsedObject != nil && o.UnparsedObject == nil {
		hasInvalidField = true
	}
	o.Owner = all.Owner

	if len(additionalProperties) > 0 {
		o.AdditionalProperties = additionalProperties
	}

	if hasInvalidField {
		return datadog.Unmarshal(bytes, &o.UnparsedObject)
	}

	return nil
}
