# Variables ====================================================================

variable "stack_name" {
  description = "Name of the stack (tag: stack-name)"
  type        = string

  validation {
    condition     = length(trimspace(var.stack_name)) > 0
    error_message = "stack_name must not be empty."
  }
}

variable "application_name" {
  description = "Application name (tag: application-name)"
  type        = string

  validation {
    condition     = length(trimspace(var.application_name)) > 0
    error_message = "application_name must not be empty."
  }
}

variable "enable_map_tag" {
  description = "Enable the AWS Migration Accelerated Program (MAP) tag"
  type        = bool
  default     = false
}

variable "project" {
  description = "Project name (tag: project)"
  type        = string

  validation {
    condition     = length(trimspace(var.project)) > 0
    error_message = "project must not be empty."
  }
}

variable "cost_center_opex" {
  description = "OPEX cost center code (tag: cost-center-opex)"
  type        = string

  validation {
    condition     = length(trimspace(var.cost_center_opex)) > 0
    error_message = "cost_center_opex must not be empty."
  }
}

variable "cost_center_capex" {
  description = "CAPEX cost center code (tag: cost-center-capex)"
  type        = string

  validation {
    condition     = length(trimspace(var.cost_center_capex)) > 0
    error_message = "cost_center_capex must not be empty."
  }
}

variable "environment" {
  description = "Deployment environment (tag: environment)"
  type        = string

  validation {
    condition     = length(trimspace(var.environment)) > 0
    error_message = "environment must not be empty."
  }
}

variable "data_classification" {
  description = "Data classification level (tag: data-classification)"
  type        = string

  validation {
    condition     = length(trimspace(var.data_classification)) > 0
    error_message = "data_classification must not be empty."
  }
}

variable "availability_tier" {
  description = "Availability tier (tag: availability-tier)"
  type        = string

  validation {
    condition     = length(trimspace(var.availability_tier)) > 0
    error_message = "availability_tier must not be empty."
  }
}

variable "app_owner" {
  description = "Application owner role/title (tag: app-owner)"
  type        = string

  validation {
    condition     = length(trimspace(var.app_owner)) > 0
    error_message = "app_owner must not be empty."
  }
}

variable "team" {
  description = "Owning team (tag: team)"
  type        = string

  validation {
    condition     = length(trimspace(var.team)) > 0
    error_message = "team must not be empty."
  }
}

variable "assignment_group" {
  description = "Support assignment group (tag: assignment-group)"
  type        = string

  validation {
    condition     = length(trimspace(var.assignment_group)) > 0
    error_message = "assignment_group must not be empty."
  }
}

variable "owner" {
  description = "Owner contact email (tag: owner)"
  type        = string

  validation {
    condition     = length(trimspace(var.owner)) > 0
    error_message = "owner must not be empty."
  }
}

variable "business_unit" {
  description = "Business unit (tag: business-unit)"
  type        = string

  validation {
    condition     = length(trimspace(var.business_unit)) > 0
    error_message = "business_unit must not be empty."
  }
}

variable "additional_tags" {
  description = <<-EOT
    Additional tags to merge with the module's baseline tags.

    Baseline tags always take precedence. If a key here collides
    with a baseline tag, the baseline value wins and this value
    is silently dropped.
  EOT
  type        = map(string)
  default     = {}

  validation {
    condition = alltrue([
      for k in keys(var.additional_tags) : can(regex("^[a-z0-9]+(-[a-z0-9]+)*$", k))
    ])
    error_message = <<-EOT
      Invalid tag key(s) detected in "additional_tags".

      All keys must be kebab-case: lowercase alphanumeric
      segments separated by single hyphens.

        valid:   cost-center, owner, data-classification
        invalid: CostCenter, cost_center, Cost-Center, cost--center

      Fix the offending key(s) to proceed.
    EOT
  }
}
