module "table_database_role_SHOPIFY_STORE_ASSOCIATION" {
  for_each = toset(["QA", "PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/table_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  table    = "SHOPIFY_STORE_ASSOCIATION"
}

module "view_database_role_SME_SHOPIFY_STORE" {
  for_each = toset(["QA", "PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/view_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  view     = "SME_SHOPIFY_STORE"
}

module "view_database_role_FANS_BY_ARTIST_ACCOUNT" {
  for_each = toset(["QA", "PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/view_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  view     = "FANS_BY_ARTIST_ACCOUNT"
}

module "view_database_role_FANS_BY_ARTIST_ACCOUNT_COUNTRY" {
  for_each = toset(["QA", "PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/view_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  view     = "FANS_BY_ARTIST_ACCOUNT_COUNTRY"
}

module "streamlit_database_role_FILEUPLOAD" {
  for_each = toset(["PROD"])
  source   = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/streamlit_access?ref=7.7.8"

  database     = var.database_name
  schema       = each.value
  streamlit_id = "FILEUPLOAD"
}

module "streamlit_database_role_SME_MERCH" {
  for_each = toset(["PROD_STREAMLIT_SME_MERCH"])
  source   = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/streamlit_access?ref=7.7.8"

  database     = var.database_name
  schema       = each.value
  streamlit_id = "SME_MERCH"
}

module "streamlit_database_role_FAN_DATA_EXPORT" {
  for_each = toset(["PROD_STREAMLIT_FAN_EXPORT"])
  source   = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/streamlit_access?ref=7.7.8"

  database     = var.database_name
  schema       = each.value
  streamlit_id = "FAN_DATA_EXPORT"
}

module "schema_streamlits_role_ROSTER_MANAGEMENT" {
  for_each = toset(["QA_STREAMLIT_ROSTER_MANAGEMENT", "PROD_STREAMLIT_ROSTER_MANAGEMENT"])
  source   = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/schema_streamlits_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
}

# Fansifter Email POC Streamlit application access in DEV_RBOMBERG schema
module "streamlit_database_role_EMAILPOC" {
  for_each = toset(["DEV_RBOMBERG"])
  source   = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/streamlit_access?ref=7.7.8"

  database     = var.database_name
  schema       = each.value
  streamlit_id = "EMAILPOC"
}

module "streamlit_database_role_TRIGGERED_SENDS" {
  source       = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/streamlit_access?ref=7.7.8"
  database     = var.database_name
  schema       = "QA_CRM_FANS"
  streamlit_id = "TRIGGERED_SENDS"
}

module "table_database_role_EVENT_SONGWHIP_FAN_CONSENT" {
  for_each = toset(["QA", "PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/table_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  table    = "EVENT_SONGWHIP_FAN_CONSENT"
}
module "table_database_role_EVENT_SONGWHIP_FAN_CONSENT_DOUBLE_OPT_IN" {
  for_each = toset(["QA", "PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/table_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  table    = "EVENT_SONGWHIP_FAN_CONSENT_DOUBLE_OPT_IN"
}
module "table_database_role_EVENT_SONGWHIP_PRESAVE_PROCESSED" {
  for_each = toset(["QA", "PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/table_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  table    = "EVENT_SONGWHIP_PRESAVE_PROCESSED"
}
module "table_database_role_FANS_BY_ARTIST_ACCOUNT_DBT" {
  for_each = toset(["QA", "PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/table_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  table    = "FANS_BY_ARTIST_ACCOUNT_DBT"
}

# Dynamic table access for AD_REPORTING_CAMPAIGN_DBT_BENELUX
module "dynamic_table_database_role_AD_REPORTING_CAMPAIGN_DBT_BENELUX" {
  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/dynamic_table_access?ref=7.7.8"

  database      = var.database_name
  schema        = "DEV_MMACHADO"
  dynamic_table = "AD_REPORTING_CAMPAIGN_DBT_BENELUX"
}

module "table_database_role_ARTIST_ROSTER_MAIN_REP" {
  for_each = toset(["PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/table_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  table    = "ARTIST_ROSTER_MAIN_REP"
}
module "table_database_role_ARTIST_ROSTER_LOCAL_REP" {
  for_each = toset(["PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/table_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
  table    = "ARTIST_ROSTER_LOCAL_REP"
}

module "view_database_role_PROD_VIEWS" {
  for_each = toset(var.prod_views_names)

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/view_access?ref=7.7.8"

  database = var.database_name
  schema   = "PROD_VIEWS"
  view     = each.value
}

module "schema_streamlits_role_FANSIFTER_BACKOFFICE" {
  for_each = toset(["PROD_STREAMLIT_FANSIFTER_BACKOFFICE"])
  source   = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/schema_streamlits_access?ref=7.7.8"

  database = var.database_name
  schema   = each.value
}

module "table_database_role_CCPA_FAN_LIST" {
  for_each = toset(["PROD"])

  source = "git@github.com:theorchard/terraform-snowflake.git//modules/roles/table_access?ref=7.7.8"

  database                = var.database_name
  schema                  = each.value
  table                   = "CCPA_FAN_LIST"
  enable_write_privileges = true
}
