defmodule Wild.Books.Author do
  use Ecto.Schema
  import Ecto.Changeset

  schema "authors" do
    field :name, :string
    field :country, :string
    field :bio, :string
    field :year_born, :string
    field :year_died, :string

    has_many :books, Wild.Books.Book

    timestamps(type: :utc_datetime)
  end

  @doc false
  def changeset(author, attrs) do
    author
    |> cast(attrs, [:name, :country, :bio, :year_born, :year_died])
    |> validate_required([:name, :country, :bio, :year_born, :year_died])
  end
end
