# ------------------------------------------------------------------------------
# 1. GLOBAL / PROJECT VARIABLES
# ------------------------------------------------------------------------------
variable "project_name" {
  description = "Project name or identifier"
  type        = string
}

variable "environment" {
  description = "Deployment environment name"
  type        = string

  validation {
    condition     = contains(["dev", "stage", "prod"], var.environment)
    error_message = "Environment must be one of: dev, stage, or prod."
  }
}

variable "env" {
  description = "Deployment environment name"
  type        = string

  validation {
    condition     = contains(["dev", "stage", "prod"], var.environment)
    error_message = "Environment must be one of: dev, stage, or prod."
  }
}

variable "aws_region" {
  description = "AWS region where resources will be provisioned"
  type        = string
  default     = "ap-south-1"

  validation {
    condition     = can(regex("^[a-z]{2}-[a-z]+-[0-9]{1}$", var.aws_region))
    error_message = "Must be a valid AWS region identifier (e.g. ap-south-1, us-east-1)."
  }
}

variable "common_tags" {
  description = "Default tags applied to all AWS resources"
  type        = map(string)
  default = {
    ManagedBy = "Terraform"
    Owner     = "DevOps"
  }
}

# ------------------------------------------------------------------------------
# 2. VPC VARIABLES
# ------------------------------------------------------------------------------
variable "vpc_cidr" {
  description = "Primary IPv4 CIDR block for the VPC"
  type        = string
  default     = "10.0.0.0/16"
}

variable "availability_zones" {
  description = "List of availability zones for multi-AZ deployment"
  type        = list(string)
  default     = ["ap-south-1a", "ap-south-1b"]
}

variable "public_subnet_cidrs" {
  description = "CIDR blocks for public subnets (ALB, NAT Gateways)"
  type        = list(string)
  default     = ["10.0.1.0/24", "10.0.2.0/24"]
}

variable "private_subnet_cidrs" {
  description = "CIDR blocks for private application subnets (ECS, EC2)"
  type        = list(string)
  default     = ["10.0.11.0/24", "10.0.12.0/24"]
}

variable "database_subnet_cidrs" {
  description = "CIDR blocks for isolated database subnets (RDS)"
  type        = list(string)
  default     = ["10.0.21.0/24", "10.0.22.0/24"]
}

variable "enable_nat_gateway" {
  description = "Enable NAT Gateway for outbound internet access from private subnets"
  type        = bool
  default     = true
}

variable "single_nat_gateway" {
  description = "Use a single NAT Gateway (true saves cost in dev; false for prod HA)"
  type        = bool
  default     = true
}

# ------------------------------------------------------------------------------
# 3. ECR VARIABLES
# ------------------------------------------------------------------------------
variable "ecr_repository_name" {
  description = "Name of the ECR repository"
  type        = string
  default     = "app-backend"
}

variable "ecr_image_tag_mutability" {
  description = "Tag mutability setting for the repository (MUTABLE or IMMUTABLE)"
  type        = string
  default     = "IMMUTABLE"
}

variable "ecr_scan_on_push" {
  description = "Scan container images for vulnerabilities on push"
  type        = bool
  default     = true
}

# ------------------------------------------------------------------------------
# 4. ECS VARIABLES
# ------------------------------------------------------------------------------
variable "ecs_cluster_name" {
  description = "Name of the ECS cluster"
  type        = string
  default     = "main-cluster"
}

variable "ecs_launch_type" {
  description = "ECS launch type (FARGATE or EC2)"
  type        = string
  default     = "FARGATE"
}

variable "container_image" {
  description = "Docker image URI and tag to deploy"
  type        = string
  default     = "nginx:latest"
}

variable "container_port" {
  description = "Port exposed by the application container"
  type        = number
  default     = 8080
}

variable "ecs_task_cpu" {
  description = "CPU units allocated to the ECS task (e.g., 256, 512, 1024)"
  type        = number
  default     = 256
}

variable "ecs_task_memory" {
  description = "Memory (in MiB) allocated to the ECS task (e.g., 512, 1024, 2048)"
  type        = number
  default     = 512
}

variable "ecs_desired_count" {
  description = "Number of running tasks for the ECS service"
  type        = number
  default     = 2
}

# ------------------------------------------------------------------------------
# 5. EC2 VARIABLES
# ------------------------------------------------------------------------------
variable "ec2_ami_id" {
  description = "AMI ID for the EC2 instance (leave empty if fetching dynamically via data source)"
  type        = string
  default     = ""
}

variable "ec2_instance_type" {
  description = "EC2 instance size"
  type        = string
  default     = "t3.micro"
}

variable "ec2_key_name" {
  description = "Name of an existing AWS Key Pair for SSH access"
  type        = string
  default     = null
}

variable "ec2_root_volume_size" {
  description = "Size of the root EBS volume in GB"
  type        = number
  default     = 20
}

# ------------------------------------------------------------------------------
# 6. RDS VARIABLES
# ------------------------------------------------------------------------------
variable "db_identifier" {
  description = "Unique identifier for the RDS instance"
  type        = string
  default     = "app-postgres-db"
}

variable "db_engine" {
  description = "Database engine type (postgres, mysql, mariadb)"
  type        = string
  default     = "postgres"
}

variable "db_engine_version" {
  description = "Database engine version"
  type        = string
  default     = "16.3"
}

variable "db_instance_class" {
  description = "RDS instance sizing"
  type        = string
  default     = "db.t4g.micro"
}

variable "db_allocated_storage" {
  description = "Initial storage size in GB"
  type        = number
  default     = 20
}

variable "db_max_allocated_storage" {
  description = "Upper limit in GB for storage autoscaling (0 disables autoscaling)"
  type        = number
  default     = 100
}

variable "db_name" {
  description = "Name of the initial database to create"
  type        = string
  default     = "appdb"
}

variable "db_username" {
  description = "Master administrator username"
  type        = string
  default     = "dbadmin"
  sensitive   = true
}

variable "db_multi_az" {
  description = "Enable Multi-AZ deployment for high availability"
  type        = bool
  default     = false
}

variable "db_backup_retention_period" {
  description = "Number of days to retain automated backups"
  type        = number
  default     = 7
}

variable "db_deletion_protection" {
  description = "Prevent accidental deletion of the database"
  type        = bool
  default     = false
}

