defmodule WcaLive.MixProject do
  use Mix.Project

  def project do
    [
      app: :wca_live,
      version: "0.1.0",
      elixir: "~> 1.17",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  def application do
    [
      mod: {WcaLive.Application, []},
      extra_applications: [:logger, :runtime_tools, :crypto]
    ]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  defp deps do
    [
      {:phoenix, "~> 1.7.6"},
      {:phoenix_ecto, "~> 4.1"},
      {:ecto_sql, "~> 3.4"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_live_dashboard, "~> 0.8.0"},
      {:telemetry_metrics, "~> 1.0"},
      {:telemetry_poller, "~> 1.0"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:req, "~> 0.5.6"},
      {:absinthe, "~> 1.7"},
      {:absinthe_plug, "~> 1.5"},
      {:absinthe_phoenix, "~> 2.0"},
      {:dataloader, "~> 2.0"},
      {:cors_plug, "~> 3.0"},
      {:pdf_generator, "~> 0.6"},
      {:dns_cluster, "~> 0.1.3"},
      {:new_relic_agent, "~> 1.0"},
      {:ex_machina, "~> 2.4", only: [:test, :dev]}
    ]
  end

  defp aliases do
    [
      setup: ["deps.get", "ecto.setup", "client.setup"],
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate", "test"],
      "client.setup": ["cmd npm install --prefix client"],
      "client.build": ["cmd npm run build --prefix client", "phx.digest"],
      "format.all": ["format", "cmd npm run format --prefix client"]
    ]
  end
end
