module "zitadel-tenant" {
  source = "../../../modules/zitadel/tenant"

  name = "fourlights"
}

module "zitadel-idp-google" {
  source  = "../../../modules/zitadel/identity-provider/google"
  wait_on = module.zitadel-tenant.installed

  org_id        = module.zitadel-tenant.org_id
  client_id     = "783390190667-quvko2l2kr9ksgeo3pn6pn6t8c1mai9n.apps.googleusercontent.com"
  client_secret = "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"

  domain = var.domain

  options = {
    scopes = ["openid", "profile", "email"]
    is_auto_creation    = true
    is_auto_update      = true
    is_creation_allowed = true
    is_linking_allowed  = true

    auto_linking = "AUTO_LINKING_OPTION_USERNAME"
  }
}

module "zitadel-user" {
  source  = "../../../modules/zitadel/user"
  wait_on = module.zitadel-tenant.installed

  org_id = module.zitadel-tenant.org_id

  first_name = "Thomas"
  last_name  = "Rijpstra"
  user_name  = "thomas@fourlights.nl"
  email      = "thomas@fourlights.nl"
}

module "zitadel-org-owner" {
  source  = "../../../modules/zitadel/tenant/role-owner"
  wait_on = module.zitadel-user.installed

  org_id  = module.zitadel-tenant.org_id
  user_id = module.zitadel-user.user_id
}

output "org_id" {
  value = module.zitadel-tenant.org_id
}

output "user_id" {
  value = module.zitadel-user.user_id
}
