/*
Daytona

Daytona AI platform API Docs

API version: 1.0
Contact: support@daytona.com
*/

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

package apiclient

import (
	"encoding/json"
	"fmt"
)

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

// TraceSpan struct for TraceSpan
type TraceSpan struct {
	// Trace identifier
	TraceId string `json:"traceId"`
	// Span identifier
	SpanId string `json:"spanId"`
	// Parent span identifier
	ParentSpanId *string `json:"parentSpanId,omitempty"`
	// Span name
	SpanName string `json:"spanName"`
	// Span start timestamp
	Timestamp string `json:"timestamp"`
	// Span duration in nanoseconds
	DurationNs float32 `json:"durationNs"`
	// Span attributes
	SpanAttributes map[string]string `json:"spanAttributes"`
	// Status code of the span
	StatusCode *string `json:"statusCode,omitempty"`
	// Status message
	StatusMessage *string `json:"statusMessage,omitempty"`
	AdditionalProperties map[string]interface{}
}

type _TraceSpan TraceSpan

// NewTraceSpan instantiates a new TraceSpan 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 NewTraceSpan(traceId string, spanId string, spanName string, timestamp string, durationNs float32, spanAttributes map[string]string) *TraceSpan {
	this := TraceSpan{}
	this.TraceId = traceId
	this.SpanId = spanId
	this.SpanName = spanName
	this.Timestamp = timestamp
	this.DurationNs = durationNs
	this.SpanAttributes = spanAttributes
	return &this
}

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

// GetTraceId returns the TraceId field value
func (o *TraceSpan) GetTraceId() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.TraceId
}

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

// SetTraceId sets field value
func (o *TraceSpan) SetTraceId(v string) {
	o.TraceId = v
}

// GetSpanId returns the SpanId field value
func (o *TraceSpan) GetSpanId() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.SpanId
}

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

// SetSpanId sets field value
func (o *TraceSpan) SetSpanId(v string) {
	o.SpanId = v
}

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

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

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

	return false
}

// SetParentSpanId gets a reference to the given string and assigns it to the ParentSpanId field.
func (o *TraceSpan) SetParentSpanId(v string) {
	o.ParentSpanId = &v
}

// GetSpanName returns the SpanName field value
func (o *TraceSpan) GetSpanName() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.SpanName
}

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

// SetSpanName sets field value
func (o *TraceSpan) SetSpanName(v string) {
	o.SpanName = v
}

// GetTimestamp returns the Timestamp field value
func (o *TraceSpan) GetTimestamp() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Timestamp
}

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

// SetTimestamp sets field value
func (o *TraceSpan) SetTimestamp(v string) {
	o.Timestamp = v
}

// GetDurationNs returns the DurationNs field value
func (o *TraceSpan) GetDurationNs() float32 {
	if o == nil {
		var ret float32
		return ret
	}

	return o.DurationNs
}

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

// SetDurationNs sets field value
func (o *TraceSpan) SetDurationNs(v float32) {
	o.DurationNs = v
}

// GetSpanAttributes returns the SpanAttributes field value
func (o *TraceSpan) GetSpanAttributes() map[string]string {
	if o == nil {
		var ret map[string]string
		return ret
	}

	return o.SpanAttributes
}

// GetSpanAttributesOk returns a tuple with the SpanAttributes field value
// and a boolean to check if the value has been set.
func (o *TraceSpan) GetSpanAttributesOk() (*map[string]string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.SpanAttributes, true
}

// SetSpanAttributes sets field value
func (o *TraceSpan) SetSpanAttributes(v map[string]string) {
	o.SpanAttributes = v
}

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

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

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

	return false
}

// SetStatusCode gets a reference to the given string and assigns it to the StatusCode field.
func (o *TraceSpan) SetStatusCode(v string) {
	o.StatusCode = &v
}

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

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

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

	return false
}

// SetStatusMessage gets a reference to the given string and assigns it to the StatusMessage field.
func (o *TraceSpan) SetStatusMessage(v string) {
	o.StatusMessage = &v
}

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

func (o TraceSpan) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["traceId"] = o.TraceId
	toSerialize["spanId"] = o.SpanId
	if !IsNil(o.ParentSpanId) {
		toSerialize["parentSpanId"] = o.ParentSpanId
	}
	toSerialize["spanName"] = o.SpanName
	toSerialize["timestamp"] = o.Timestamp
	toSerialize["durationNs"] = o.DurationNs
	toSerialize["spanAttributes"] = o.SpanAttributes
	if !IsNil(o.StatusCode) {
		toSerialize["statusCode"] = o.StatusCode
	}
	if !IsNil(o.StatusMessage) {
		toSerialize["statusMessage"] = o.StatusMessage
	}

	for key, value := range o.AdditionalProperties {
		toSerialize[key] = value
	}

	return toSerialize, nil
}

func (o *TraceSpan) 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{
		"traceId",
		"spanId",
		"spanName",
		"timestamp",
		"durationNs",
		"spanAttributes",
	}

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

	varTraceSpan := _TraceSpan{}

	err = json.Unmarshal(data, &varTraceSpan)

	if err != nil {
		return err
	}

	*o = TraceSpan(varTraceSpan)

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

	if err = json.Unmarshal(data, &additionalProperties); err == nil {
		delete(additionalProperties, "traceId")
		delete(additionalProperties, "spanId")
		delete(additionalProperties, "parentSpanId")
		delete(additionalProperties, "spanName")
		delete(additionalProperties, "timestamp")
		delete(additionalProperties, "durationNs")
		delete(additionalProperties, "spanAttributes")
		delete(additionalProperties, "statusCode")
		delete(additionalProperties, "statusMessage")
		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableTraceSpan struct {
	value *TraceSpan
	isSet bool
}

func (v NullableTraceSpan) Get() *TraceSpan {
	return v.value
}

func (v *NullableTraceSpan) Set(val *TraceSpan) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableTraceSpan(val *TraceSpan) *NullableTraceSpan {
	return &NullableTraceSpan{value: val, isSet: true}
}

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

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


