=begin
#Hatchet API

#The Hatchet API

The version of the OpenAPI document: 1.0.0

Generated by: https://openapi-generator.tech
Generator version: 7.14.0

=end

require 'date'
require 'time'

module HatchetSdkRest
  class V1TaskTiming
    attr_accessor :metadata

    # The depth of the task in the waterfall.
    attr_accessor :depth

    attr_accessor :status

    # The display name of the task run.
    attr_accessor :task_display_name

    # The external ID of the task.
    attr_accessor :task_external_id

    # The ID of the task.
    attr_accessor :task_id

    # The timestamp the task was inserted.
    attr_accessor :task_inserted_at

    # The ID of the tenant.
    attr_accessor :tenant_id

    # The external ID of the parent task.
    attr_accessor :parent_task_external_id

    # The timestamp the task run was queued.
    attr_accessor :queued_at

    # The timestamp the task run started.
    attr_accessor :started_at

    # The timestamp the task run finished.
    attr_accessor :finished_at

    # The external ID of the workflow run.
    attr_accessor :workflow_run_id

    # The number of retries of the task.
    attr_accessor :retry_count

    # The attempt number of the task.
    attr_accessor :attempt

    class EnumAttributeValidator
      attr_reader :datatype
      attr_reader :allowable_values

      def initialize(datatype, allowable_values)
        @allowable_values = allowable_values.map do |value|
          case datatype.to_s
          when /Integer/i
            value.to_i
          when /Float/i
            value.to_f
          else
            value
          end
        end
      end

      def valid?(value)
        !value || allowable_values.include?(value)
      end
    end

    # Attribute mapping from ruby-style variable name to JSON key.
    def self.attribute_map
      {
        :'metadata' => :'metadata',
        :'depth' => :'depth',
        :'status' => :'status',
        :'task_display_name' => :'taskDisplayName',
        :'task_external_id' => :'taskExternalId',
        :'task_id' => :'taskId',
        :'task_inserted_at' => :'taskInsertedAt',
        :'tenant_id' => :'tenantId',
        :'parent_task_external_id' => :'parentTaskExternalId',
        :'queued_at' => :'queuedAt',
        :'started_at' => :'startedAt',
        :'finished_at' => :'finishedAt',
        :'workflow_run_id' => :'workflowRunId',
        :'retry_count' => :'retryCount',
        :'attempt' => :'attempt'
      }
    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
      {
        :'metadata' => :'APIResourceMeta',
        :'depth' => :'Integer',
        :'status' => :'V1TaskStatus',
        :'task_display_name' => :'String',
        :'task_external_id' => :'String',
        :'task_id' => :'Integer',
        :'task_inserted_at' => :'Time',
        :'tenant_id' => :'String',
        :'parent_task_external_id' => :'String',
        :'queued_at' => :'Time',
        :'started_at' => :'Time',
        :'finished_at' => :'Time',
        :'workflow_run_id' => :'String',
        :'retry_count' => :'Integer',
        :'attempt' => :'Integer'
      }
    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 `HatchetSdkRest::V1TaskTiming` 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 `HatchetSdkRest::V1TaskTiming`. 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?(:'metadata')
        self.metadata = attributes[:'metadata']
      else
        self.metadata = nil
      end

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

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

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

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

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

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

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

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

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

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

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

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

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

      if attributes.key?(:'attempt')
        self.attempt = attributes[:'attempt']
      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 @metadata.nil?
        invalid_properties.push('invalid value for "metadata", metadata cannot be nil.')
      end

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

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

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

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

      if @task_external_id.to_s.length > 36
        invalid_properties.push('invalid value for "task_external_id", the character length must be smaller than or equal to 36.')
      end

      if @task_external_id.to_s.length < 36
        invalid_properties.push('invalid value for "task_external_id", the character length must be greater than or equal to 36.')
      end

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

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

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

      if @tenant_id.to_s.length > 36
        invalid_properties.push('invalid value for "tenant_id", the character length must be smaller than or equal to 36.')
      end

      if @tenant_id.to_s.length < 36
        invalid_properties.push('invalid value for "tenant_id", the character length must be greater than or equal to 36.')
      end

      if !@parent_task_external_id.nil? && @parent_task_external_id.to_s.length > 36
        invalid_properties.push('invalid value for "parent_task_external_id", the character length must be smaller than or equal to 36.')
      end

      if !@parent_task_external_id.nil? && @parent_task_external_id.to_s.length < 36
        invalid_properties.push('invalid value for "parent_task_external_id", the character length must be greater than or equal to 36.')
      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 @metadata.nil?
      return false if @depth.nil?
      return false if @status.nil?
      return false if @task_display_name.nil?
      return false if @task_external_id.nil?
      return false if @task_external_id.to_s.length > 36
      return false if @task_external_id.to_s.length < 36
      return false if @task_id.nil?
      return false if @task_inserted_at.nil?
      return false if @tenant_id.nil?
      return false if @tenant_id.to_s.length > 36
      return false if @tenant_id.to_s.length < 36
      return false if !@parent_task_external_id.nil? && @parent_task_external_id.to_s.length > 36
      return false if !@parent_task_external_id.nil? && @parent_task_external_id.to_s.length < 36
      true
    end

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

      @metadata = metadata
    end

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

      @depth = depth
    end

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

      @status = status
    end

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

      @task_display_name = task_display_name
    end

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

      if task_external_id.to_s.length > 36
        fail ArgumentError, 'invalid value for "task_external_id", the character length must be smaller than or equal to 36.'
      end

      if task_external_id.to_s.length < 36
        fail ArgumentError, 'invalid value for "task_external_id", the character length must be greater than or equal to 36.'
      end

      @task_external_id = task_external_id
    end

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

      @task_id = task_id
    end

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

      @task_inserted_at = task_inserted_at
    end

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

      if tenant_id.to_s.length > 36
        fail ArgumentError, 'invalid value for "tenant_id", the character length must be smaller than or equal to 36.'
      end

      if tenant_id.to_s.length < 36
        fail ArgumentError, 'invalid value for "tenant_id", the character length must be greater than or equal to 36.'
      end

      @tenant_id = tenant_id
    end

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

      if parent_task_external_id.to_s.length > 36
        fail ArgumentError, 'invalid value for "parent_task_external_id", the character length must be smaller than or equal to 36.'
      end

      if parent_task_external_id.to_s.length < 36
        fail ArgumentError, 'invalid value for "parent_task_external_id", the character length must be greater than or equal to 36.'
      end

      @parent_task_external_id = parent_task_external_id
    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 &&
          metadata == o.metadata &&
          depth == o.depth &&
          status == o.status &&
          task_display_name == o.task_display_name &&
          task_external_id == o.task_external_id &&
          task_id == o.task_id &&
          task_inserted_at == o.task_inserted_at &&
          tenant_id == o.tenant_id &&
          parent_task_external_id == o.parent_task_external_id &&
          queued_at == o.queued_at &&
          started_at == o.started_at &&
          finished_at == o.finished_at &&
          workflow_run_id == o.workflow_run_id &&
          retry_count == o.retry_count &&
          attempt == o.attempt
    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
      [metadata, depth, status, task_display_name, task_external_id, task_id, task_inserted_at, tenant_id, parent_task_external_id, queued_at, started_at, finished_at, workflow_run_id, retry_count, attempt].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

    # Deserializes the data based on type
    # @param string type Data type
    # @param string value Value to be deserialized
    # @return [Object] Deserialized data
    def self._deserialize(type, value)
      case type.to_sym
      when :Time
        Time.parse(value)
      when :Date
        Date.parse(value)
      when :String
        value.to_s
      when :Integer
        value.to_i
      when :Float
        value.to_f
      when :Boolean
        if value.to_s =~ /\A(true|t|yes|y|1)\z/i
          true
        else
          false
        end
      when :Object
        # generic object (usually a Hash), return directly
        value
      when /\AArray<(?<inner_type>.+)>\z/
        inner_type = Regexp.last_match[:inner_type]
        value.map { |v| _deserialize(inner_type, v) }
      when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
        k_type = Regexp.last_match[:k_type]
        v_type = Regexp.last_match[:v_type]
        {}.tap do |hash|
          value.each do |k, v|
            hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
          end
        end
      else # model
        # models (e.g. Pet) or oneOf
        klass = HatchetSdkRest.const_get(type)
        klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
      end
    end

    # Returns the string representation of the object
    # @return [String] String presentation of the object
    def to_s
      to_hash.to_s
    end

    # to_body is an alias to to_hash (backward compatibility)
    # @return [Hash] Returns the object in the form of hash
    def to_body
      to_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

    # Outputs non-array value in the form of hash
    # For object, use to_hash. Otherwise, just return the value
    # @param [Object] value Any valid value
    # @return [Hash] Returns the value in the form of hash
    def _to_hash(value)
      if value.is_a?(Array)
        value.compact.map { |v| _to_hash(v) }
      elsif value.is_a?(Hash)
        {}.tap do |hash|
          value.each { |k, v| hash[k] = _to_hash(v) }
        end
      elsif value.respond_to? :to_hash
        value.to_hash
      else
        value
      end
    end

  end

end
