=begin
#Daytona

#Daytona AI platform API Docs

The version of the OpenAPI document: 1.0
Contact: support@daytona.com
Generated by: https://openapi-generator.tech
Generator version: 7.21.0

=end

require 'date'
require 'time'

module DaytonaApiClient
  class TraceSpan < ApiModelBase
    # Trace identifier
    attr_accessor :trace_id

    # Span identifier
    attr_accessor :span_id

    # Parent span identifier
    attr_accessor :parent_span_id

    # Span name
    attr_accessor :span_name

    # Span start timestamp
    attr_accessor :timestamp

    # Span duration in nanoseconds
    attr_accessor :duration_ns

    # Span attributes
    attr_accessor :span_attributes

    # Status code of the span
    attr_accessor :status_code

    # Status message
    attr_accessor :status_message

    # Attribute mapping from ruby-style variable name to JSON key.
    def self.attribute_map
      {
        :'trace_id' => :'traceId',
        :'span_id' => :'spanId',
        :'parent_span_id' => :'parentSpanId',
        :'span_name' => :'spanName',
        :'timestamp' => :'timestamp',
        :'duration_ns' => :'durationNs',
        :'span_attributes' => :'spanAttributes',
        :'status_code' => :'statusCode',
        :'status_message' => :'statusMessage'
      }
    end

    # Returns attribute mapping this model knows about
    def self.acceptable_attribute_map
      attribute_map
    end

    # Returns all the JSON keys this model knows about
    def self.acceptable_attributes
      acceptable_attribute_map.values
    end

    # Attribute type mapping.
    def self.openapi_types
      {
        :'trace_id' => :'String',
        :'span_id' => :'String',
        :'parent_span_id' => :'String',
        :'span_name' => :'String',
        :'timestamp' => :'String',
        :'duration_ns' => :'Float',
        :'span_attributes' => :'Hash<String, String>',
        :'status_code' => :'String',
        :'status_message' => :'String'
      }
    end

    # List of attributes with nullable: true
    def self.openapi_nullable
      Set.new([
      ])
    end

    # Initializes the object
    # @param [Hash] attributes Model attributes in the form of hash
    def initialize(attributes = {})
      if (!attributes.is_a?(Hash))
        fail ArgumentError, "The input argument (attributes) must be a hash in `DaytonaApiClient::TraceSpan` initialize method"
      end

      # check to see if the attribute exists and convert string to symbol for hash key
      acceptable_attribute_map = self.class.acceptable_attribute_map
      attributes = attributes.each_with_object({}) { |(k, v), h|
        if (!acceptable_attribute_map.key?(k.to_sym))
          fail ArgumentError, "`#{k}` is not a valid attribute in `DaytonaApiClient::TraceSpan`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
        end
        h[k.to_sym] = v
      }

      if attributes.key?(:'trace_id')
        self.trace_id = attributes[:'trace_id']
      else
        self.trace_id = nil
      end

      if attributes.key?(:'span_id')
        self.span_id = attributes[:'span_id']
      else
        self.span_id = nil
      end

      if attributes.key?(:'parent_span_id')
        self.parent_span_id = attributes[:'parent_span_id']
      end

      if attributes.key?(:'span_name')
        self.span_name = attributes[:'span_name']
      else
        self.span_name = nil
      end

      if attributes.key?(:'timestamp')
        self.timestamp = attributes[:'timestamp']
      else
        self.timestamp = nil
      end

      if attributes.key?(:'duration_ns')
        self.duration_ns = attributes[:'duration_ns']
      else
        self.duration_ns = nil
      end

      if attributes.key?(:'span_attributes')
        if (value = attributes[:'span_attributes']).is_a?(Hash)
          self.span_attributes = value
        end
      else
        self.span_attributes = nil
      end

      if attributes.key?(:'status_code')
        self.status_code = attributes[:'status_code']
      end

      if attributes.key?(:'status_message')
        self.status_message = attributes[:'status_message']
      end
    end

    # Show invalid properties with the reasons. Usually used together with valid?
    # @return Array for valid properties with the reasons
    def list_invalid_properties
      warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
      invalid_properties = Array.new
      if @trace_id.nil?
        invalid_properties.push('invalid value for "trace_id", trace_id cannot be nil.')
      end

      if @span_id.nil?
        invalid_properties.push('invalid value for "span_id", span_id cannot be nil.')
      end

      if @span_name.nil?
        invalid_properties.push('invalid value for "span_name", span_name cannot be nil.')
      end

      if @timestamp.nil?
        invalid_properties.push('invalid value for "timestamp", timestamp cannot be nil.')
      end

      if @duration_ns.nil?
        invalid_properties.push('invalid value for "duration_ns", duration_ns cannot be nil.')
      end

      if @span_attributes.nil?
        invalid_properties.push('invalid value for "span_attributes", span_attributes cannot be nil.')
      end

      invalid_properties
    end

    # Check to see if the all the properties in the model are valid
    # @return true if the model is valid
    def valid?
      warn '[DEPRECATED] the `valid?` method is obsolete'
      return false if @trace_id.nil?
      return false if @span_id.nil?
      return false if @span_name.nil?
      return false if @timestamp.nil?
      return false if @duration_ns.nil?
      return false if @span_attributes.nil?
      true
    end

    # Custom attribute writer method with validation
    # @param [Object] trace_id Value to be assigned
    def trace_id=(trace_id)
      if trace_id.nil?
        fail ArgumentError, 'trace_id cannot be nil'
      end

      @trace_id = trace_id
    end

    # Custom attribute writer method with validation
    # @param [Object] span_id Value to be assigned
    def span_id=(span_id)
      if span_id.nil?
        fail ArgumentError, 'span_id cannot be nil'
      end

      @span_id = span_id
    end

    # Custom attribute writer method with validation
    # @param [Object] span_name Value to be assigned
    def span_name=(span_name)
      if span_name.nil?
        fail ArgumentError, 'span_name cannot be nil'
      end

      @span_name = span_name
    end

    # Custom attribute writer method with validation
    # @param [Object] timestamp Value to be assigned
    def timestamp=(timestamp)
      if timestamp.nil?
        fail ArgumentError, 'timestamp cannot be nil'
      end

      @timestamp = timestamp
    end

    # Custom attribute writer method with validation
    # @param [Object] duration_ns Value to be assigned
    def duration_ns=(duration_ns)
      if duration_ns.nil?
        fail ArgumentError, 'duration_ns cannot be nil'
      end

      @duration_ns = duration_ns
    end

    # Custom attribute writer method with validation
    # @param [Object] span_attributes Value to be assigned
    def span_attributes=(span_attributes)
      if span_attributes.nil?
        fail ArgumentError, 'span_attributes cannot be nil'
      end

      @span_attributes = span_attributes
    end

    # Checks equality by comparing each attribute.
    # @param [Object] Object to be compared
    def ==(o)
      return true if self.equal?(o)
      self.class == o.class &&
          trace_id == o.trace_id &&
          span_id == o.span_id &&
          parent_span_id == o.parent_span_id &&
          span_name == o.span_name &&
          timestamp == o.timestamp &&
          duration_ns == o.duration_ns &&
          span_attributes == o.span_attributes &&
          status_code == o.status_code &&
          status_message == o.status_message
    end

    # @see the `==` method
    # @param [Object] Object to be compared
    def eql?(o)
      self == o
    end

    # Calculates hash code according to all attributes.
    # @return [Integer] Hash code
    def hash
      [trace_id, span_id, parent_span_id, span_name, timestamp, duration_ns, span_attributes, status_code, status_message].hash
    end

    # Builds the object from hash
    # @param [Hash] attributes Model attributes in the form of hash
    # @return [Object] Returns the model itself
    def self.build_from_hash(attributes)
      return nil unless attributes.is_a?(Hash)
      attributes = attributes.transform_keys(&:to_sym)
      transformed_hash = {}
      openapi_types.each_pair do |key, type|
        if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
          transformed_hash["#{key}"] = nil
        elsif type =~ /\AArray<(.*)>/i
          # check to ensure the input is an array given that the attribute
          # is documented as an array but the input is not
          if attributes[attribute_map[key]].is_a?(Array)
            transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
          end
        elsif !attributes[attribute_map[key]].nil?
          transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
        end
      end
      new(transformed_hash)
    end

    # Returns the object in the form of hash
    # @return [Hash] Returns the object in the form of hash
    def to_hash
      hash = {}
      self.class.attribute_map.each_pair do |attr, param|
        value = self.send(attr)
        if value.nil?
          is_nullable = self.class.openapi_nullable.include?(attr)
          next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
        end

        hash[param] = _to_hash(value)
      end
      hash
    end

  end

end
