defmodule Berrypod.Media.FaviconVariant do
  use Ecto.Schema
  import Ecto.Changeset

  @primary_key {:id, :binary_id, autogenerate: true}
  @foreign_key_type :binary_id

  schema "favicon_variants" do
    field :source_image_id, :binary_id
    field :png_32, :binary
    field :png_180, :binary
    field :png_192, :binary
    field :png_512, :binary
    field :svg, :string
    field :generated_at, :utc_datetime

    timestamps(type: :utc_datetime)
  end

  @doc false
  def changeset(variant, attrs) do
    variant
    |> cast(attrs, [:source_image_id, :png_32, :png_180, :png_192, :png_512, :svg, :generated_at])
    |> validate_required([:source_image_id, :generated_at])
  end
end
