=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 Workspace < ApiModelBase
    # The ID of the sandbox
    attr_accessor :id

    # The organization ID of the sandbox
    attr_accessor :organization_id

    # The name of the sandbox
    attr_accessor :name

    # The snapshot used for the sandbox
    attr_accessor :snapshot

    # The user associated with the project
    attr_accessor :user

    # Environment variables for the sandbox
    attr_accessor :env

    # Labels for the sandbox
    attr_accessor :labels

    # Whether the sandbox http preview is public
    attr_accessor :public

    # Whether to block all network access for the sandbox
    attr_accessor :network_block_all

    # Comma-separated list of allowed CIDR network addresses for the sandbox
    attr_accessor :network_allow_list

    # The target environment for the sandbox
    attr_accessor :target

    # The CPU quota for the sandbox
    attr_accessor :cpu

    # The GPU quota for the sandbox
    attr_accessor :gpu

    # The memory quota for the sandbox
    attr_accessor :memory

    # The disk quota for the sandbox
    attr_accessor :disk

    # The state of the sandbox
    attr_accessor :state

    # The desired state of the sandbox
    attr_accessor :desired_state

    # The error reason of the sandbox
    attr_accessor :error_reason

    # Whether the sandbox error is recoverable.
    attr_accessor :recoverable

    # The state of the backup
    attr_accessor :backup_state

    # The creation timestamp of the last backup
    attr_accessor :backup_created_at

    # Auto-stop interval in minutes (0 means disabled)
    attr_accessor :auto_stop_interval

    # Auto-archive interval in minutes
    attr_accessor :auto_archive_interval

    # Auto-delete interval in minutes (negative value means disabled, 0 means delete immediately upon stopping)
    attr_accessor :auto_delete_interval

    # Array of volumes attached to the sandbox
    attr_accessor :volumes

    # Build information for the sandbox
    attr_accessor :build_info

    # The creation timestamp of the sandbox
    attr_accessor :created_at

    # The last update timestamp of the sandbox
    attr_accessor :updated_at

    # The last activity timestamp of the sandbox
    attr_accessor :last_activity_at

    # The class of the sandbox
    attr_accessor :_class

    # The version of the daemon running in the sandbox
    attr_accessor :daemon_version

    # The runner ID of the sandbox
    attr_accessor :runner_id

    # The toolbox proxy URL for the sandbox
    attr_accessor :toolbox_proxy_url

    # The image used for the workspace
    attr_accessor :image

    # The state of the snapshot
    attr_accessor :snapshot_state

    # The creation timestamp of the last snapshot
    attr_accessor :snapshot_created_at

    # Additional information about the sandbox
    attr_accessor :info

    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
      {
        :'id' => :'id',
        :'organization_id' => :'organizationId',
        :'name' => :'name',
        :'snapshot' => :'snapshot',
        :'user' => :'user',
        :'env' => :'env',
        :'labels' => :'labels',
        :'public' => :'public',
        :'network_block_all' => :'networkBlockAll',
        :'network_allow_list' => :'networkAllowList',
        :'target' => :'target',
        :'cpu' => :'cpu',
        :'gpu' => :'gpu',
        :'memory' => :'memory',
        :'disk' => :'disk',
        :'state' => :'state',
        :'desired_state' => :'desiredState',
        :'error_reason' => :'errorReason',
        :'recoverable' => :'recoverable',
        :'backup_state' => :'backupState',
        :'backup_created_at' => :'backupCreatedAt',
        :'auto_stop_interval' => :'autoStopInterval',
        :'auto_archive_interval' => :'autoArchiveInterval',
        :'auto_delete_interval' => :'autoDeleteInterval',
        :'volumes' => :'volumes',
        :'build_info' => :'buildInfo',
        :'created_at' => :'createdAt',
        :'updated_at' => :'updatedAt',
        :'last_activity_at' => :'lastActivityAt',
        :'_class' => :'class',
        :'daemon_version' => :'daemonVersion',
        :'runner_id' => :'runnerId',
        :'toolbox_proxy_url' => :'toolboxProxyUrl',
        :'image' => :'image',
        :'snapshot_state' => :'snapshotState',
        :'snapshot_created_at' => :'snapshotCreatedAt',
        :'info' => :'info'
      }
    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
      {
        :'id' => :'String',
        :'organization_id' => :'String',
        :'name' => :'String',
        :'snapshot' => :'String',
        :'user' => :'String',
        :'env' => :'Hash<String, String>',
        :'labels' => :'Hash<String, String>',
        :'public' => :'Boolean',
        :'network_block_all' => :'Boolean',
        :'network_allow_list' => :'String',
        :'target' => :'String',
        :'cpu' => :'Float',
        :'gpu' => :'Float',
        :'memory' => :'Float',
        :'disk' => :'Float',
        :'state' => :'SandboxState',
        :'desired_state' => :'SandboxDesiredState',
        :'error_reason' => :'String',
        :'recoverable' => :'Boolean',
        :'backup_state' => :'String',
        :'backup_created_at' => :'String',
        :'auto_stop_interval' => :'Float',
        :'auto_archive_interval' => :'Float',
        :'auto_delete_interval' => :'Float',
        :'volumes' => :'Array<SandboxVolume>',
        :'build_info' => :'BuildInfo',
        :'created_at' => :'String',
        :'updated_at' => :'String',
        :'last_activity_at' => :'String',
        :'_class' => :'String',
        :'daemon_version' => :'String',
        :'runner_id' => :'String',
        :'toolbox_proxy_url' => :'String',
        :'image' => :'String',
        :'snapshot_state' => :'String',
        :'snapshot_created_at' => :'String',
        :'info' => :'SandboxInfo'
      }
    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::Workspace` 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::Workspace`. 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?(:'id')
        self.id = attributes[:'id']
      else
        self.id = nil
      end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if @toolbox_proxy_url.nil?
        invalid_properties.push('invalid value for "toolbox_proxy_url", toolbox_proxy_url 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 @id.nil?
      return false if @organization_id.nil?
      return false if @name.nil?
      return false if @user.nil?
      return false if @env.nil?
      return false if @labels.nil?
      return false if @public.nil?
      return false if @network_block_all.nil?
      return false if @target.nil?
      return false if @cpu.nil?
      return false if @gpu.nil?
      return false if @memory.nil?
      return false if @disk.nil?
      backup_state_validator = EnumAttributeValidator.new('String', ["None", "Pending", "InProgress", "Completed", "Error", "unknown_default_open_api"])
      return false unless backup_state_validator.valid?(@backup_state)
      _class_validator = EnumAttributeValidator.new('String', ["small", "medium", "large", "unknown_default_open_api"])
      return false unless _class_validator.valid?(@_class)
      return false if @toolbox_proxy_url.nil?
      snapshot_state_validator = EnumAttributeValidator.new('String', ["None", "Pending", "InProgress", "Completed", "Error", "unknown_default_open_api"])
      return false unless snapshot_state_validator.valid?(@snapshot_state)
      true
    end

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

      @id = id
    end

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

      @organization_id = organization_id
    end

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

      @name = name
    end

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

      @user = user
    end

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

      @env = env
    end

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

      @labels = labels
    end

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

      @public = public
    end

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

      @network_block_all = network_block_all
    end

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

      @target = target
    end

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

      @cpu = cpu
    end

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

      @gpu = gpu
    end

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

      @memory = memory
    end

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

      @disk = disk
    end

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] backup_state Object to be assigned
    def backup_state=(backup_state)
      validator = EnumAttributeValidator.new('String', ["None", "Pending", "InProgress", "Completed", "Error", "unknown_default_open_api"])
      unless validator.valid?(backup_state)
        fail ArgumentError, "invalid value for \"backup_state\", must be one of #{validator.allowable_values}."
      end
      @backup_state = backup_state
    end

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] _class Object to be assigned
    def _class=(_class)
      validator = EnumAttributeValidator.new('String', ["small", "medium", "large", "unknown_default_open_api"])
      unless validator.valid?(_class)
        fail ArgumentError, "invalid value for \"_class\", must be one of #{validator.allowable_values}."
      end
      @_class = _class
    end

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

      @toolbox_proxy_url = toolbox_proxy_url
    end

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] snapshot_state Object to be assigned
    def snapshot_state=(snapshot_state)
      validator = EnumAttributeValidator.new('String', ["None", "Pending", "InProgress", "Completed", "Error", "unknown_default_open_api"])
      unless validator.valid?(snapshot_state)
        fail ArgumentError, "invalid value for \"snapshot_state\", must be one of #{validator.allowable_values}."
      end
      @snapshot_state = snapshot_state
    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 &&
          id == o.id &&
          organization_id == o.organization_id &&
          name == o.name &&
          snapshot == o.snapshot &&
          user == o.user &&
          env == o.env &&
          labels == o.labels &&
          public == o.public &&
          network_block_all == o.network_block_all &&
          network_allow_list == o.network_allow_list &&
          target == o.target &&
          cpu == o.cpu &&
          gpu == o.gpu &&
          memory == o.memory &&
          disk == o.disk &&
          state == o.state &&
          desired_state == o.desired_state &&
          error_reason == o.error_reason &&
          recoverable == o.recoverable &&
          backup_state == o.backup_state &&
          backup_created_at == o.backup_created_at &&
          auto_stop_interval == o.auto_stop_interval &&
          auto_archive_interval == o.auto_archive_interval &&
          auto_delete_interval == o.auto_delete_interval &&
          volumes == o.volumes &&
          build_info == o.build_info &&
          created_at == o.created_at &&
          updated_at == o.updated_at &&
          last_activity_at == o.last_activity_at &&
          _class == o._class &&
          daemon_version == o.daemon_version &&
          runner_id == o.runner_id &&
          toolbox_proxy_url == o.toolbox_proxy_url &&
          image == o.image &&
          snapshot_state == o.snapshot_state &&
          snapshot_created_at == o.snapshot_created_at &&
          info == o.info
    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
      [id, organization_id, name, snapshot, user, env, labels, public, network_block_all, network_allow_list, target, cpu, gpu, memory, disk, state, desired_state, error_reason, recoverable, backup_state, backup_created_at, auto_stop_interval, auto_archive_interval, auto_delete_interval, volumes, build_info, created_at, updated_at, last_activity_at, _class, daemon_version, runner_id, toolbox_proxy_url, image, snapshot_state, snapshot_created_at, info].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
