defmodule BullX.Ecto.UUIDv7 do
  @moduledoc """
  Ecto UUID type for PostgreSQL primary keys that must be generated by BullX.

  Use this on UUID primary keys instead of relying on PostgreSQL defaults:

      @primary_key {:id, BullX.Ecto.UUIDv7, autogenerate: true}
  """

  use Ecto.Type

  @impl true
  def type, do: :uuid

  @impl true
  def cast(value), do: Ecto.UUID.cast(value)

  @impl true
  def load(value), do: Ecto.UUID.load(value)

  @impl true
  def dump(value), do: Ecto.UUID.dump(value)

  @impl true
  def autogenerate, do: BullX.Ext.gen_uuid_v7()
end
