lib/forgejo/models/branch_protection.rb



=begin
#Forgejo API

#This documentation describes the Forgejo API.

The version of the OpenAPI document: 10.0.0-121-28886cd+gitea-1.22.0

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

=end

require 'date'
require 'time'

module Forgejo
  # BranchProtection represents a branch protection for a repository
  class BranchProtection
    attr_accessor :apply_to_admins

    attr_accessor :approvals_whitelist_teams

    attr_accessor :approvals_whitelist_username

    attr_accessor :block_on_official_review_requests

    attr_accessor :block_on_outdated_branch

    attr_accessor :block_on_rejected_reviews

    # Deprecated: true
    attr_accessor :branch_name

    attr_accessor :created_at

    attr_accessor :dismiss_stale_approvals

    attr_accessor :enable_approvals_whitelist

    attr_accessor :enable_merge_whitelist

    attr_accessor :enable_push

    attr_accessor :enable_push_whitelist

    attr_accessor :enable_status_check

    attr_accessor :ignore_stale_approvals

    attr_accessor :merge_whitelist_teams

    attr_accessor :merge_whitelist_usernames

    attr_accessor :protected_file_patterns

    attr_accessor :push_whitelist_deploy_keys

    attr_accessor :push_whitelist_teams

    attr_accessor :push_whitelist_usernames

    attr_accessor :require_signed_commits

    attr_accessor :required_approvals

    attr_accessor :rule_name

    attr_accessor :status_check_contexts

    attr_accessor :unprotected_file_patterns

    attr_accessor :updated_at

    # Attribute mapping from ruby-style variable name to JSON key.
    def self.attribute_map
      {
        :'apply_to_admins' => :'apply_to_admins',
        :'approvals_whitelist_teams' => :'approvals_whitelist_teams',
        :'approvals_whitelist_username' => :'approvals_whitelist_username',
        :'block_on_official_review_requests' => :'block_on_official_review_requests',
        :'block_on_outdated_branch' => :'block_on_outdated_branch',
        :'block_on_rejected_reviews' => :'block_on_rejected_reviews',
        :'branch_name' => :'branch_name',
        :'created_at' => :'created_at',
        :'dismiss_stale_approvals' => :'dismiss_stale_approvals',
        :'enable_approvals_whitelist' => :'enable_approvals_whitelist',
        :'enable_merge_whitelist' => :'enable_merge_whitelist',
        :'enable_push' => :'enable_push',
        :'enable_push_whitelist' => :'enable_push_whitelist',
        :'enable_status_check' => :'enable_status_check',
        :'ignore_stale_approvals' => :'ignore_stale_approvals',
        :'merge_whitelist_teams' => :'merge_whitelist_teams',
        :'merge_whitelist_usernames' => :'merge_whitelist_usernames',
        :'protected_file_patterns' => :'protected_file_patterns',
        :'push_whitelist_deploy_keys' => :'push_whitelist_deploy_keys',
        :'push_whitelist_teams' => :'push_whitelist_teams',
        :'push_whitelist_usernames' => :'push_whitelist_usernames',
        :'require_signed_commits' => :'require_signed_commits',
        :'required_approvals' => :'required_approvals',
        :'rule_name' => :'rule_name',
        :'status_check_contexts' => :'status_check_contexts',
        :'unprotected_file_patterns' => :'unprotected_file_patterns',
        :'updated_at' => :'updated_at'
      }
    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
      {
        :'apply_to_admins' => :'Boolean',
        :'approvals_whitelist_teams' => :'Array<String>',
        :'approvals_whitelist_username' => :'Array<String>',
        :'block_on_official_review_requests' => :'Boolean',
        :'block_on_outdated_branch' => :'Boolean',
        :'block_on_rejected_reviews' => :'Boolean',
        :'branch_name' => :'String',
        :'created_at' => :'Time',
        :'dismiss_stale_approvals' => :'Boolean',
        :'enable_approvals_whitelist' => :'Boolean',
        :'enable_merge_whitelist' => :'Boolean',
        :'enable_push' => :'Boolean',
        :'enable_push_whitelist' => :'Boolean',
        :'enable_status_check' => :'Boolean',
        :'ignore_stale_approvals' => :'Boolean',
        :'merge_whitelist_teams' => :'Array<String>',
        :'merge_whitelist_usernames' => :'Array<String>',
        :'protected_file_patterns' => :'String',
        :'push_whitelist_deploy_keys' => :'Boolean',
        :'push_whitelist_teams' => :'Array<String>',
        :'push_whitelist_usernames' => :'Array<String>',
        :'require_signed_commits' => :'Boolean',
        :'required_approvals' => :'Integer',
        :'rule_name' => :'String',
        :'status_check_contexts' => :'Array<String>',
        :'unprotected_file_patterns' => :'String',
        :'updated_at' => :'Time'
      }
    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 `Forgejo::BranchProtection` 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 `Forgejo::BranchProtection`. 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?(:'apply_to_admins')
        self.apply_to_admins = attributes[:'apply_to_admins']
      end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if attributes.key?(:'updated_at')
        self.updated_at = attributes[:'updated_at']
      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
      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'
      true
    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 &&
          apply_to_admins == o.apply_to_admins &&
          approvals_whitelist_teams == o.approvals_whitelist_teams &&
          approvals_whitelist_username == o.approvals_whitelist_username &&
          block_on_official_review_requests == o.block_on_official_review_requests &&
          block_on_outdated_branch == o.block_on_outdated_branch &&
          block_on_rejected_reviews == o.block_on_rejected_reviews &&
          branch_name == o.branch_name &&
          created_at == o.created_at &&
          dismiss_stale_approvals == o.dismiss_stale_approvals &&
          enable_approvals_whitelist == o.enable_approvals_whitelist &&
          enable_merge_whitelist == o.enable_merge_whitelist &&
          enable_push == o.enable_push &&
          enable_push_whitelist == o.enable_push_whitelist &&
          enable_status_check == o.enable_status_check &&
          ignore_stale_approvals == o.ignore_stale_approvals &&
          merge_whitelist_teams == o.merge_whitelist_teams &&
          merge_whitelist_usernames == o.merge_whitelist_usernames &&
          protected_file_patterns == o.protected_file_patterns &&
          push_whitelist_deploy_keys == o.push_whitelist_deploy_keys &&
          push_whitelist_teams == o.push_whitelist_teams &&
          push_whitelist_usernames == o.push_whitelist_usernames &&
          require_signed_commits == o.require_signed_commits &&
          required_approvals == o.required_approvals &&
          rule_name == o.rule_name &&
          status_check_contexts == o.status_check_contexts &&
          unprotected_file_patterns == o.unprotected_file_patterns &&
          updated_at == o.updated_at
    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
      [apply_to_admins, approvals_whitelist_teams, approvals_whitelist_username, block_on_official_review_requests, block_on_outdated_branch, block_on_rejected_reviews, branch_name, created_at, dismiss_stale_approvals, enable_approvals_whitelist, enable_merge_whitelist, enable_push, enable_push_whitelist, enable_status_check, ignore_stale_approvals, merge_whitelist_teams, merge_whitelist_usernames, protected_file_patterns, push_whitelist_deploy_keys, push_whitelist_teams, push_whitelist_usernames, require_signed_commits, required_approvals, rule_name, status_check_contexts, unprotected_file_patterns, updated_at].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 = Forgejo.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