defmodule Wild.BookReads do
  @moduledoc """
  The BookReads context.
  """

  import Ecto.Query, warn: false
  alias Wild.Repo

  alias Wild.BookReads.BookRead

  @doc """
  Returns the list of book_reads.

  ## Examples

      iex> list_book_reads()
      [%BookRead{}, ...]

  """
  def list_book_reads do
    Repo.all(BookRead)
  end

  @doc """
  Gets a single book_read.

  Raises `Ecto.NoResultsError` if the Book read does not exist.

  ## Examples

      iex> get_book_read!(123)
      %BookRead{}

      iex> get_book_read!(456)
      ** (Ecto.NoResultsError)

  """
  def get_book_read!(id), do: Repo.get!(BookRead, id)

  @doc """
  Creates a book_read.

  ## Examples

      iex> create_book_read(%{field: value})
      {:ok, %BookRead{}}

      iex> create_book_read(%{field: bad_value})
      {:error, %Ecto.Changeset{}}

  """
  def create_book_read(attrs \\ %{}) do
    %BookRead{}
    |> BookRead.changeset(attrs)
    |> Repo.insert()
  end

  @doc """
  Updates a book_read.

  ## Examples

      iex> update_book_read(book_read, %{field: new_value})
      {:ok, %BookRead{}}

      iex> update_book_read(book_read, %{field: bad_value})
      {:error, %Ecto.Changeset{}}

  """
  def update_book_read(%BookRead{} = book_read, attrs) do
    book_read
    |> BookRead.changeset(attrs)
    |> Repo.update()
  end

  @doc """
  Deletes a book_read.

  ## Examples

      iex> delete_book_read(book_read)
      {:ok, %BookRead{}}

      iex> delete_book_read(book_read)
      {:error, %Ecto.Changeset{}}

  """
  def delete_book_read(%BookRead{} = book_read) do
    Repo.delete(book_read)
  end

  @doc """
  Returns an `%Ecto.Changeset{}` for tracking book_read changes.

  ## Examples

      iex> change_book_read(book_read)
      %Ecto.Changeset{data: %BookRead{}}

  """
  def change_book_read(%BookRead{} = book_read, attrs \\ %{}) do
    BookRead.changeset(book_read, attrs)
  end
end
