defmodule MediaServerWeb.WebhooksController do
  use MediaServerWeb, :controller

  require Logger

  def create(conn, %{"id" => "movie", "eventType" => "Download"} = params) do
    MediaServerWeb.Actions.Movie.handle_info({:added, params})

    Logger.info(params)

    conn
    |> send_resp(201, "Ok")
  end

  def create(conn, %{"id" => "movie", "eventType" => "MovieDelete"}) do
    MediaServerWeb.Actions.Movie.handle_info({:deleted})

    conn
    |> send_resp(201, "Ok")
  end

  def create(conn, %{"id" => "movie", "eventType" => "MovieFileDelete"}) do
    MediaServerWeb.Actions.Movie.handle_info({:deleted_file})

    conn
    |> send_resp(201, "Ok")
  end

  def create(conn, %{"id" => "series", "eventType" => "Download"} = params) do
    MediaServerWeb.Actions.Series.handle_info({:added, params})

    Logger.info(params)

    conn
    |> send_resp(201, "Ok")
  end

  def create(conn, %{"id" => "series", "eventType" => "SeriesDelete"}) do
    MediaServerWeb.Actions.Series.handle_info({:deleted})

    conn
    |> send_resp(201, "Ok")
  end

  def create(conn, %{"id" => "series", "eventType" => "EpisodeFileDelete"}) do
    MediaServerWeb.Actions.Series.handle_info({:deleted_episode_file})

    conn
    |> send_resp(201, "Ok")
  end

  def create(conn, params) do
    Logger.info(params)

    conn
    |> send_resp(200, "Ok")
  end
end
