import Config

# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources.
config :orcasite, OrcasiteWeb.Endpoint,
  url: [host: "localhost"],
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  secret_key_base: "ZaTk5BBbg4BWCa+zQ0rjJxr9T5WqSEUt3oS0bd1Ct1SOFQg1HgBjPJaGffsNXZU3",
  watchers: [
    esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
    tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
  ]

# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# command from your terminal:
#
#     openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout priv/server.key -out priv/server.pem
#
# The `http:` config above can be replaced with:
#
#     https: [port: 4000, keyfile: "priv/server.key", certfile: "priv/server.pem"],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.

# Watch static and templates for browser reloading.
config :orcasite, OrcasiteWeb.Endpoint,
  live_reload: [
    patterns: [
      ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
      ~r{priv/gettext/.*(po)$},
      ~r{lib/orcasite_web/(controllers|live|components)/.*(ex|heex)$}
    ]
  ]

config :orcasite, dev_routes: true

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: {Orcasite.Logger, :format}

# Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 100

# Configure your database
config :orcasite, Orcasite.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: System.get_env("POSTGRES_USER") || "postgres",
  password: System.get_env("POSTGRES_PASSWORD") || "postgres",
  database: System.get_env("POSTGRES_DATABASE") || "orcasite_dev",
  hostname: System.get_env("POSTGRES_HOST") || "localhost",
  stacktrace: true,
  port: System.get_env("POSTGRES_PORT") || 5432,
  pool_size: 10,
  types: Orcasite.PostgresTypes

config :orcasite,
       :orcasite_s3_url,
       System.get_env("ORCASITE_S3_URL") || "https://s3-us-west-2.amazonaws.com/orcasite"

# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime

config :phoenix_live_view,
  debug_heex_annotations: true,
  debug_attributes: true,
  enable_expensive_runtime_checks: true

# Disable swoosh api client as it is only required for production adapters.
config :swoosh, :api_client, false

# Redis-based pubsub and cache configuration
# config :orcasite,
#        :pub_sub_redis,
#        enabled: true,
#        node_name: Base.encode16(:crypto.strong_rand_bytes(6)),
#        host: System.get_env("REDIS_HOST") || "127.0.0.1",
#        port: String.to_integer(System.get_env("REDIS_PORT") || "6379")

# config :orcasite, Orcasite.Cache,
#   conn_opts: [
#     # Redix options
#     host: System.get_env("REDIS_HOST") || "127.0.0.1",
#     port: String.to_integer(System.get_env("REDIS_PORT") || "6379")
#   ]
# config :orcasite, :cache_adapter, NebulexRedisAdapter

config :orcasite, :cache_adapter, Nebulex.Adapters.Local

config :hammer,
  backend: {Hammer.Backend.ETS, [expiry_ms: 60_000 * 60 * 4, cleanup_interval_ms: 60_000 * 10]}

config :orcasite, OrcasiteWeb.BasicAuth, username: "admin", password: "password"
config :ash, :policies, show_policy_breakdowns?: true, log_policy_breakdowns: :debug
config :ash_graphql, :policies, show_policy_breakdowns?: true
config :ash, :pub_sub, debug?: true
config :orcasite, Orcasite.Radio, graphql: [show_raised_errors?: true]
config :orcasite, Orcasite.Accounts, graphql: [show_raised_errors?: true]

config :ex_aws,
  access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, {:awscli, "orcasound", 1000}, :instance_role],
  secret_access_key: [
    {:system, "AWS_SECRET_ACCESS_KEY"},
    {:awscli, "orcasound", 1000},
    :instance_role
  ],
  region: "us-west-2"

config :orcasite,
  audio_image_bucket: System.get_env("ORCASITE_AUDIO_IMAGE_BUCKET", "dev-audio-viz"),
  audio_image_bucket_region: System.get_env("ORCASITE_AUDIO_IMAGE_BUCKET_REGION", "us-west-2")

# Disable these by setting them to false in your env or dev.secret.exs
config :orcasite, enable_seed_from_prod: System.get_env("ENABLE_SEED_FROM_PROD", "true") == "true"

config :orcasite,
  auto_update_seeded_records: System.get_env("AUTO_UPDATE_SEEDED_RECORDS", "true") == "true"

config :orcasite,
  auto_delete_seeded_records: System.get_env("AUTO_DELETE_SEEDED_RECORDS", "true") == "true"

config :orcasite, :env, :dev

# Import locally defined secrets & overrides. This must remain at the bottom of
# this file so it overrides the configuration defined above.
if __DIR__ |> Path.join("dev.secret.exs") |> File.exists?() do
  import_config("dev.secret.exs")
end
