use Mix.Config

# For production, we configure the host to read the PORT
# from the system environment. Therefore, you will need
# to set PORT=80 before running your server.
#
# You should also configure the url host to something
# meaningful, we use this information when generating URLs.
#
# Finally, we also include the path to a manifest
# containing the digested version of static files. This
# manifest is generated by the mix phoenix.digest task
# which you typically run after static files are built.
# General application configuration
config :alloy_ci,
  app_id: "${GITHUB_APP_ID}",
  app_url: "${GITHUB_APP_URL}",
  private_key: "${GITHUB_PRIVATE_KEY}",
  runner_registration_token: "${RUNNER_REGISTRATION_TOKEN}",
  server_url: "${SERVER_URL}"

config :alloy_ci, AlloyCi.Web.Endpoint,
  http: [port: "${PORT}"],
  url: [host: "${HOST}", port: "${PORT}", scheme: "https"],
  # force_ssl: [rewrite_on: [:x_forwarded_proto]],
  # url: [host: "alloy-ci.com", port: 443],
  # force_ssl: [hsts: true],
  # https: [
  #   port: 443,
  #   keyfile: System.get_env("SSL_KEY_PATH"),
  #   certfile: System.get_env("SSL_CERT_PATH")
  # ],
  cache_static_manifest: "priv/static/cache_manifest.json",
  secret_key_base: "${SECRET_KEY_BASE}",
  server: true,
  root: "."

# Do not print debug messages in production
config :logger, level: :info

# Configure your database
config :alloy_ci, AlloyCi.Repo,
  url: "${DATABASE_URL}",
  pool_size: 20

# ssl: true

config :sentry,
  dsn: "${SENTRY_DSN}",
  environment_name: :prod,
  enable_source_code_context: true,
  root_source_code_path: File.cwd!(),
  tags: %{
    env: "production"
  },
  included_environments: [:prod]

# Configures Uberauth
config :ueberauth, Ueberauth,
  providers: [
    github: {
      Ueberauth.Strategy.Github,
      [
        default_scope: "user,repo",
        send_redirect_uri: false
      ]
    },
    identity: {Ueberauth.Strategy.Identity, [callback_methods: ["POST"]]}
  ]

# Configures Guardian
config :alloy_ci, AlloyCi.Guardian,
  issuer: "AlloyCi.Prod",
  secret_key: "${SECRET_KEY_BASE}"

# Configures Notifiers
config :alloy_ci, AlloyCi.Notifier,
  slack: "${ENABLE_SLACK_NOTIFICATIONS}",
  email: "${ENABLE_EMAIL_NOTIFICATIONS}"

# Configures Email Settings
config :alloy_ci, AlloyCi.Notifiers.Email,
  adapter: Bamboo.SMTPAdapter,
  server: "${SMTP_SERVER}",
  port: "${SMTP_PORT}",
  username: "${SMTP_USERNAME}",
  password: "${SMTP_PASSWORD}",
  # can be `:always` or `:never`
  tls: :if_available,
  # comma seprated values (e.g. "tlsv1.1,tlsv1.2")
  allowed_tls_versions: "${ALLOWED_TLS_VERSIONS}",
  ssl: "${SMTP_SSL}",
  retries: 1,
  from_address: "${FROM_ADDRESS}",
  reply_to_address: "${REPLY_TO_ADDRESS}"

# Configures Slack settings
config :alloy_ci, AlloyCi.Notifiers.Slack,
  channel: "${SLACK_CHANNEL}",
  service_name: "${SLACK_SERVICE_NAME}",
  hook_url: "${SLACK_HOOK_URL}",
  icon_emoji: "${SLACK_ICON}"

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to the previous section and set your `:url` port to 443:
#
#     config :alloy_ci, AlloyCi.Endpoint,
#       ...
#       url: [host: "example.com", port: 443],
#       https: [port: 443,
#               keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
#               certfile: System.get_env("SOME_APP_SSL_CERT_PATH")]
#
# Where those two env variables return an absolute path to
# the key and cert in disk or a relative path inside priv,
# for example "priv/ssl/server.key".
#
# We also recommend setting `force_ssl`, ensuring no data is
# ever sent via http, always redirecting to https:
#
#     config :alloy_ci, AlloyCi.Endpoint,
#       force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.

# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start the server for all endpoints:
#
#     config :phoenix, :serve_endpoints, true
#
# Alternatively, you can configure exactly which server to
# start per endpoint:
#
#     config :alloy_ci, AlloyCi.Endpoint, server: true
#

# Finally import the config/prod.secret.exs
# which should be versioned separately.
# import_config "prod.secret.exs"
