# Variables ====================================================================

variable "name_prefix" {
  description = "Prefix prepended to resource names created by this module"
  type        = string

  validation {
    condition     = length(trimspace(var.name_prefix)) > 0
    error_message = "name_prefix must not be empty."
  }
}

variable "tags" {
  description = "Tags applied to all resources in this module."
  type        = map(string)
  default     = {}
}

variable "resource_shares" {
  description = <<-EOT
    Map of RAM resource share definitions.
    resource_arns and principals are required to be explicitly passed in
    to ensure deterministic, auditable sharing relationships.
  EOT
  type = map(object({
    name_suffix               = string
    resource_arns             = list(string)
    principals                = list(string)
    allow_external_principals = optional(bool, false)
    permission_arns           = optional(list(string))

    tags = optional(map(string), {})
  }))
  default = {}

  validation {
    condition = alltrue([
      for k, v in var.resource_shares : length(trimspace(v.name_suffix)) > 0
    ])
    error_message = "Each resource share must specify a non-empty name_suffix."
  }

  validation {
    condition = alltrue([
      for k, v in var.resource_shares : length(v.resource_arns) > 0
    ])
    error_message = "Each resource share must specify at least one resource ARN."
  }

  validation {
    condition = alltrue([
      for k, v in var.resource_shares : length(v.principals) > 0
    ])
    error_message = "Each resource share must specify at least one principal."
  }
}
