variable "database_name" {
  type        = string
  description = "The name of the database (must be upper-case)."
}

variable "db_data_retention_time_in_days" {
  type        = number
  description = "Number of days for which Snowflake retains historical data for performing Time Travel actions (SELECT, CLONE, UNDROP) on the object. A value of 0 effectively disables Time Travel for the specified database. Default value for this field is set to -1, which is a fallback to use Snowflake default. For more information, see Understanding & Using Time Travel."
  default     = null
}

variable "read_role_name" {
  type        = string
  description = "Override the name of the read-only role for the database. If not specified, the role name will be <var.database_name>_DB_READ"
  default     = null
}

variable "read_write_role_name" {
  type        = string
  description = "Override the name of the read-write role for the database. If not specified, the role name will be <var.database_name>_DB_READWRITE"
  default     = null
}

variable "create_schema_role_name" {
  type        = string
  description = "Override the name of the create-schema role for the database. If not specified, the role name will be <var.database_name>_DB_CREATE_SCHEMA"
  default     = null
}

variable "schemas" {
  type = list(object({
    name                   = string
    is_managed             = optional(bool, true)
    create_roles           = optional(bool, true)
    read_role_name         = optional(string) # Use this to override the schema's read-only role name. Defaults to <database_name>_DB_<schema_name>_SCHEMA_READ
    read_write_role_name   = optional(string) # Use this to override the schema's read-write role name. Defaults to <database_name>_DB_<schema_name>_SCHEMA_READ
    data_retention_days    = optional(number, 1)
    is_transient           = optional(bool, false)
    log_level              = optional(string)
    trace_level            = optional(string)
    create_deployment_role = optional(bool, false)
  }))
  description = "A list of schemas to create in the database"
  default     = []

  validation {
    # Check that deployment_warehouse_role set
    condition = alltrue([
      for schema in var.schemas :
      !(schema.create_deployment_role) || var.deployment_warehouse_role != ""
    ])
    error_message = "deployment_warehouse_role must be set if any schema has create_deployment_role property set to true."
  }
}

variable "enable_account_roles" {
  type        = bool
  description = "Enable creation of account scoped roles"
  default     = false
}

variable "enable_database_roles" {
  type        = bool
  description = "Enable creation of database scoped roles"
  default     = true
}

variable "deployment_warehouse_role" {
  type        = string
  description = "Warehouse usage role which will be granted to schema deployment role if it is enabled."
  default     = ""
}

variable "grant_roles_to_sysadmin" {
  type        = bool
  description = "Whether to grant all created roles to SYSADMIN"
  default     = true
}

variable "grant_read_role_to_all_db_read_role" {
  type        = bool
  description = "Whether to grant created read role to ALL_DB_READ role"
  default     = true
}

variable "grant_streamlit_usage_to_all_streamlit_usage" {
  type        = bool
  description = "Whether to grant streamlit usage to ALL_STREAMLIT_USAGE role"
  default     = true
}
