@spec primary_for_item(Ecto.UUID.t()) :: PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t() | nil
Returns the primary supplier-info row for an item, or nil if none is marked primary.
Context for managing the phoenix_kit_cat_item_supplier_info junction table.
Each row links a catalogue item to a supplier (local or CRM-sourced) and carries a snapshot of the supplier's name at write time so the record stays readable even after renaming or deletion.
At most one row per item may have is_primary: true — enforced by a partial
unique index and by set_primary/1, which uses a transaction to clear any
existing primary before promoting the target row.
Creates a supplier-info row.
Deletes a supplier-info row.
Fetches a supplier-info row by UUID. Returns nil if not found.
Lists all supplier-info rows for an item, ordered by position then inserted_at.
Returns the primary supplier-info row for an item, or nil if none is marked primary.
Promotes a supplier-info row to primary for its item.
Updates a supplier-info row.
@spec create( map(), keyword() ) :: {:ok, PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t()} | {:error, Ecto.Changeset.t(PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t())}
Creates a supplier-info row.
When the item has no primary supplier yet, the newly linked row is auto-promoted to primary (an item with suppliers but no primary is a valid state only when the user explicitly demotes it).
@spec delete( PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t(), keyword() ) :: {:ok, PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t()} | {:error, Ecto.Changeset.t(PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t())}
Deletes a supplier-info row.
@spec get(Ecto.UUID.t()) :: PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t() | nil
Fetches a supplier-info row by UUID. Returns nil if not found.
@spec list_for_item(Ecto.UUID.t()) :: [ PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t() ]
Lists all supplier-info rows for an item, ordered by position then inserted_at.
@spec primary_for_item(Ecto.UUID.t()) :: PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t() | nil
Returns the primary supplier-info row for an item, or nil if none is marked primary.
@spec set_primary( PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t(), keyword() ) :: {:ok, PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t()} | {:error, any()}
Promotes a supplier-info row to primary for its item.
Runs in a transaction: clears is_primary on all sibling rows first,
then sets is_primary: true on the target. Respects the partial unique
index — concurrent callers produce a constraint violation rather than
double-marking.
@spec update(PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t(), map(), keyword()) :: {:ok, PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t()} | {:error, Ecto.Changeset.t(PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t())}
Updates a supplier-info row.