defmodule Bwc.Card do
  use Ecto.Schema
  import Ecto.Changeset

  schema "cards" do
    field :title, :string
    field :description, :string
    field :picture, :string
    field :played, :boolean
    timestamps()
  end

  def delete(%Bwc.Card{} = card), do: Bwc.delete_card(card)

  def changeset(card, attrs \\ %{}) do
    card
    |> cast(attrs, [:title, :picture, :description, :played])
    |> validate_required(:title)
    |> validate_length(:title, min: 3)
  end

  def format_description(card) do
    card.description
  end

end
