# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.

defmodule GoogleApi.OrgPolicy.V2.Model.GoogleCloudOrgpolicyV2PolicySpecPolicyRule do
  @moduledoc """
  A rule used to express this policy.

  ## Attributes

  *   `allowAll` (*type:* `boolean()`, *default:* `nil`) - Setting this to true means that all values are allowed. This field can be set only in policies for list constraints.
  *   `condition` (*type:* `GoogleApi.OrgPolicy.V2.Model.GoogleTypeExpr.t`, *default:* `nil`) - A condition which determines whether this rule is used in the evaluation of the policy. When set, the `expression` field in the `Expr' must include from 1 to 10 subexpressions, joined by the "||" or "&&" operators. Each subexpression must be of the form "resource.matchTag('/tag_key_short_name, 'tag_value_short_name')". or "resource.matchTagId('tagKeys/key_id', 'tagValues/value_id')". where key_name and value_name are the resource names for Label Keys and Values. These names are available from the Tag Manager Service. An example expression is: "resource.matchTag('123456789/environment, 'prod')". or "resource.matchTagId('tagKeys/123', 'tagValues/456')".
  *   `denyAll` (*type:* `boolean()`, *default:* `nil`) - Setting this to true means that all values are denied. This field can be set only in policies for list constraints.
  *   `enforce` (*type:* `boolean()`, *default:* `nil`) - If `true`, then the policy is enforced. If `false`, then any configuration is acceptable. This field can be set only in policies for boolean constraints.
  *   `parameters` (*type:* `map()`, *default:* `nil`) - Optional. Required for managed constraints if parameters are defined. Passes parameter values when policy enforcement is enabled. Ensure that parameter value types match those defined in the constraint definition. For example: { "allowedLocations" : ["us-east1", "us-west1"], "allowAll" : true }
  *   `values` (*type:* `GoogleApi.OrgPolicy.V2.Model.GoogleCloudOrgpolicyV2PolicySpecPolicyRuleStringValues.t`, *default:* `nil`) - List of values to be used for this policy rule. This field can be set only in policies for list constraints.
  """

  use GoogleApi.Gax.ModelBase

  @type t :: %__MODULE__{
          :allowAll => boolean() | nil,
          :condition => GoogleApi.OrgPolicy.V2.Model.GoogleTypeExpr.t() | nil,
          :denyAll => boolean() | nil,
          :enforce => boolean() | nil,
          :parameters => map() | nil,
          :values =>
            GoogleApi.OrgPolicy.V2.Model.GoogleCloudOrgpolicyV2PolicySpecPolicyRuleStringValues.t()
            | nil
        }

  field(:allowAll)
  field(:condition, as: GoogleApi.OrgPolicy.V2.Model.GoogleTypeExpr)
  field(:denyAll)
  field(:enforce)
  field(:parameters, type: :map)

  field(:values,
    as: GoogleApi.OrgPolicy.V2.Model.GoogleCloudOrgpolicyV2PolicySpecPolicyRuleStringValues
  )
end

defimpl Poison.Decoder,
  for: GoogleApi.OrgPolicy.V2.Model.GoogleCloudOrgpolicyV2PolicySpecPolicyRule do
  def decode(value, options) do
    GoogleApi.OrgPolicy.V2.Model.GoogleCloudOrgpolicyV2PolicySpecPolicyRule.decode(value, options)
  end
end

defimpl Poison.Encoder,
  for: GoogleApi.OrgPolicy.V2.Model.GoogleCloudOrgpolicyV2PolicySpecPolicyRule do
  def encode(value, options) do
    GoogleApi.Gax.ModelBase.encode(value, options)
  end
end
