# Variables ====================================================================

variable "name" {
  description = "Name for the Transit Gateway."
  type        = string
}

variable "description" {
  description = "Description of the Transit Gateway."
  type        = string
  default     = ""
}

variable "amazon_side_asn" {
  description = "BGP ASN for the Amazon side. Valid ranges: 64512–65534 (16-bit private) or 4200000000–4294967294 (32-bit private)."
  type        = number
  default     = 64512

  validation {
    condition = (
      (var.amazon_side_asn >= 64512 && var.amazon_side_asn <= 65534) ||
      (var.amazon_side_asn >= 4200000000 && var.amazon_side_asn <= 4294967294)
    )
    error_message = "amazon_side_asn must be in 64512–65534 or 4200000000–4294967294."
  }
}

variable "auto_accept_shared_attachments" {
  description = "Auto-accept cross-account VPC attachments. Must be 'enable' or 'disable'."
  type        = string
  default     = "disable"

  validation {
    condition     = contains(["enable", "disable"], var.auto_accept_shared_attachments)
    error_message = "auto_accept_shared_attachments must be 'enable' or 'disable'."
  }
}

variable "default_route_table_association" {
  description = "Associate new attachments with the default TGW route table. Must be 'enable' or 'disable'."
  type        = string
  default     = "enable"

  validation {
    condition     = contains(["enable", "disable"], var.default_route_table_association)
    error_message = "default_route_table_association must be 'enable' or 'disable'."
  }
}

variable "default_route_table_propagation" {
  description = "Propagate attachment routes to the default TGW route table. Must be 'enable' or 'disable'."
  type        = string
  default     = "enable"

  validation {
    condition     = contains(["enable", "disable"], var.default_route_table_propagation)
    error_message = "default_route_table_propagation must be 'enable' or 'disable'."
  }
}

variable "dns_support" {
  description = "DNS resolution across VPC attachments. Must be 'enable' or 'disable'."
  type        = string
  default     = "enable"

  validation {
    condition     = contains(["enable", "disable"], var.dns_support)
    error_message = "dns_support must be 'enable' or 'disable'."
  }
}

variable "vpn_ecmp_support" {
  description = "ECMP routing for VPN attachments. Must be 'enable' or 'disable'."
  type        = string
  default     = "enable"

  validation {
    condition     = contains(["enable", "disable"], var.vpn_ecmp_support)
    error_message = "vpn_ecmp_support must be 'enable' or 'disable'."
  }
}

variable "multicast_support" {
  description = "Enable multicast support. Cannot be changed after TGW creation — set intentionally."
  type        = string
  default     = "disable"

  validation {
    condition     = contains(["enable", "disable"], var.multicast_support)
    error_message = "multicast_support must be 'enable' or 'disable'."
  }
}

variable "ram_share_name" {
  description = "Name for the RAM resource share. Set to null to skip RAM sharing entirely."
  type        = string
  default     = null
}

variable "ram_allow_external_principals" {
  description = "Allow external principals (outside the AWS Organization) in the RAM share."
  type        = bool
  default     = false
}

variable "ram_principals" {
  description = "List of AWS account IDs or AWS Organizations ARNs to share the TGW with via RAM. Requires ram_share_name to be set."
  type        = list(string)
  default     = []

  validation {
    condition = alltrue([
      for p in var.ram_principals :
      can(regex("^\\d{12}$", p)) || can(regex("^arn:aws:organizations::", p))
    ])
    error_message = "Each ram_principal must be a 12-digit AWS account ID or an AWS Organizations ARN (arn:aws:organizations::...)."
  }
}

variable "route_tables" {
  description = "Map of additional TGW route tables to create beyond the default. Key is a logical identifier, value contains the Name tag."
  type = map(object({
    name = string
  }))
  default = {}
}

variable "tags" {
  description = "Tags to apply to all resources in this module."
  type        = map(string)
  default     = {}
}
