=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 V1TaskSummary
    attr_accessor :metadata

    # The timestamp the task was created.
    attr_accessor :created_at

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

    # The input of the task run.
    attr_accessor :input

    # The number of spawned children tasks
    attr_accessor :num_spawned_children

    # The output of the task run (for the latest run)
    attr_accessor :output

    attr_accessor :status

    # 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 type of the workflow (whether it's a DAG or a task)
    attr_accessor :type

    attr_accessor :workflow_id

    # The external ID of the workflow run
    attr_accessor :workflow_run_external_id

    # The action ID of the task.
    attr_accessor :action_id

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

    # The attempt number of the task.
    attr_accessor :attempt

    # Additional metadata for the task run.
    attr_accessor :additional_metadata

    # The list of children tasks
    attr_accessor :children

    # The duration of the task run, in milliseconds.
    attr_accessor :duration

    # The error message of the task run (for the latest run)
    attr_accessor :error_message

    # The timestamp the task run finished.
    attr_accessor :finished_at

    # The timestamp the task run started.
    attr_accessor :started_at

    # The step ID of the task.
    attr_accessor :step_id

    attr_accessor :workflow_name

    # The version ID of the workflow
    attr_accessor :workflow_version_id

    attr_accessor :workflow_config

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

    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',
        :'created_at' => :'createdAt',
        :'display_name' => :'displayName',
        :'input' => :'input',
        :'num_spawned_children' => :'numSpawnedChildren',
        :'output' => :'output',
        :'status' => :'status',
        :'task_external_id' => :'taskExternalId',
        :'task_id' => :'taskId',
        :'task_inserted_at' => :'taskInsertedAt',
        :'tenant_id' => :'tenantId',
        :'type' => :'type',
        :'workflow_id' => :'workflowId',
        :'workflow_run_external_id' => :'workflowRunExternalId',
        :'action_id' => :'actionId',
        :'retry_count' => :'retryCount',
        :'attempt' => :'attempt',
        :'additional_metadata' => :'additionalMetadata',
        :'children' => :'children',
        :'duration' => :'duration',
        :'error_message' => :'errorMessage',
        :'finished_at' => :'finishedAt',
        :'started_at' => :'startedAt',
        :'step_id' => :'stepId',
        :'workflow_name' => :'workflowName',
        :'workflow_version_id' => :'workflowVersionId',
        :'workflow_config' => :'workflowConfig',
        :'parent_task_external_id' => :'parentTaskExternalId'
      }
    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',
        :'created_at' => :'Time',
        :'display_name' => :'String',
        :'input' => :'Object',
        :'num_spawned_children' => :'Integer',
        :'output' => :'Object',
        :'status' => :'V1TaskStatus',
        :'task_external_id' => :'String',
        :'task_id' => :'Integer',
        :'task_inserted_at' => :'Time',
        :'tenant_id' => :'String',
        :'type' => :'V1WorkflowType',
        :'workflow_id' => :'String',
        :'workflow_run_external_id' => :'String',
        :'action_id' => :'String',
        :'retry_count' => :'Integer',
        :'attempt' => :'Integer',
        :'additional_metadata' => :'Object',
        :'children' => :'Array<V1TaskSummary>',
        :'duration' => :'Integer',
        :'error_message' => :'String',
        :'finished_at' => :'Time',
        :'started_at' => :'Time',
        :'step_id' => :'String',
        :'workflow_name' => :'String',
        :'workflow_version_id' => :'String',
        :'workflow_config' => :'Object',
        :'parent_task_external_id' => :'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 `HatchetSdkRest::V1TaskSummary` 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::V1TaskSummary`. 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?(:'created_at')
        self.created_at = attributes[:'created_at']
      else
        self.created_at = nil
      end

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

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

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

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

      if attributes.key?(:'status')
        self.status = attributes[:'status']
      else
        self.status = 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?(:'type')
        self.type = attributes[:'type']
      else
        self.type = nil
      end

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

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

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

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

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

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

      if attributes.key?(:'children')
        if (value = attributes[:'children']).is_a?(Array)
          self.children = value
        end
      end

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

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

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

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

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

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

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

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

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

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

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

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

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

      if @status.nil?
        invalid_properties.push('invalid value for "status", status 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 @type.nil?
        invalid_properties.push('invalid value for "type", type cannot be nil.')
      end

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

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

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

      if !@step_id.nil? && @step_id.to_s.length < 36
        invalid_properties.push('invalid value for "step_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 @created_at.nil?
      return false if @display_name.nil?
      return false if @input.nil?
      return false if @num_spawned_children.nil?
      return false if @output.nil?
      return false if @status.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 @type.nil?
      return false if @workflow_id.nil?
      return false if @workflow_run_external_id.nil?
      return false if !@step_id.nil? && @step_id.to_s.length > 36
      return false if !@step_id.nil? && @step_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] created_at Value to be assigned
    def created_at=(created_at)
      if created_at.nil?
        fail ArgumentError, 'created_at cannot be nil'
      end

      @created_at = created_at
    end

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

      @display_name = display_name
    end

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

      @input = input
    end

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

      @num_spawned_children = num_spawned_children
    end

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

      @output = output
    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_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] type Value to be assigned
    def type=(type)
      if type.nil?
        fail ArgumentError, 'type cannot be nil'
      end

      @type = type
    end

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

      @workflow_id = workflow_id
    end

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

      @workflow_run_external_id = workflow_run_external_id
    end

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

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

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

      @step_id = step_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 &&
          created_at == o.created_at &&
          display_name == o.display_name &&
          input == o.input &&
          num_spawned_children == o.num_spawned_children &&
          output == o.output &&
          status == o.status &&
          task_external_id == o.task_external_id &&
          task_id == o.task_id &&
          task_inserted_at == o.task_inserted_at &&
          tenant_id == o.tenant_id &&
          type == o.type &&
          workflow_id == o.workflow_id &&
          workflow_run_external_id == o.workflow_run_external_id &&
          action_id == o.action_id &&
          retry_count == o.retry_count &&
          attempt == o.attempt &&
          additional_metadata == o.additional_metadata &&
          children == o.children &&
          duration == o.duration &&
          error_message == o.error_message &&
          finished_at == o.finished_at &&
          started_at == o.started_at &&
          step_id == o.step_id &&
          workflow_name == o.workflow_name &&
          workflow_version_id == o.workflow_version_id &&
          workflow_config == o.workflow_config &&
          parent_task_external_id == o.parent_task_external_id
    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, created_at, display_name, input, num_spawned_children, output, status, task_external_id, task_id, task_inserted_at, tenant_id, type, workflow_id, workflow_run_external_id, action_id, retry_count, attempt, additional_metadata, children, duration, error_message, finished_at, started_at, step_id, workflow_name, workflow_version_id, workflow_config, parent_task_external_id].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
