 defmodule Tilex.Notifications do
+  @timezone Application.get_env(:tilex, :date_display_tz, "America/Chicago")
+
   use GenServer
 
   alias Ecto.{Changeset, DateTime}

  ### Server API

  def init(_) do
    {:ok, :nostate}
  end

  def handle_cast({:post_created, %Post{} = post}, :nostate) do

  def notifiers(notifiers_supervisor \\ NotifiersSupervisor) do
    notifiers_supervisor.children()
  end

  defp schedule_report do
    timezone =
      case Timex.Timezone.get(@timezone) do
        {:error, _} -> "America/Chicago"
        zone -> zone
      end

    milliseconds_until_next_monday_nine_am =
      timezone
      |> Timex.now()
      |> Timex.shift(days: 7)
      |> Timex.beginning_of_week()
      |> Timex.shift(hours: 9)
      |> Timex.diff(
        Timex.now(timezone),
        :milliseconds
      )

    Process.send_after(
      __MODULE__,
      :generate_page_views_report,
      milliseconds_until_next_monday_nine_am
    )
  end
end
