# `PhoenixKitCatalogue.Catalogue.Links`
[🔗](https://github.com/BeamLabEU/phoenix_kit_catalogue/blob/0.1.14/lib/phoenix_kit_catalogue/catalogue/links.ex#L1)

Manufacturer ↔ Supplier many-to-many links.

Add and remove individual links via `link_*`/`unlink_*`; sync the
full set for one side via `sync_*`. Bulk syncs run inside a single
transaction and emit one summary activity entry (added + removed
counts).

Public surface is re-exported from `PhoenixKitCatalogue.Catalogue`.

# `link_manufacturer_supplier`

```elixir
@spec link_manufacturer_supplier(Ecto.UUID.t(), Ecto.UUID.t()) ::
  {:ok, PhoenixKitCatalogue.Schemas.ManufacturerSupplier.t()}
  | {:error,
     Ecto.Changeset.t(PhoenixKitCatalogue.Schemas.ManufacturerSupplier.t())}
```

Creates a many-to-many link between a manufacturer and a supplier.

Returns `{:error, changeset}` if the link already exists (unique constraint).

# `linked_manufacturer_uuids`

```elixir
@spec linked_manufacturer_uuids(Ecto.UUID.t()) :: [Ecto.UUID.t()]
```

Returns a list of manufacturer UUIDs linked to a supplier.

# `linked_supplier_uuids`

```elixir
@spec linked_supplier_uuids(Ecto.UUID.t()) :: [Ecto.UUID.t()]
```

Returns a list of supplier UUIDs linked to a manufacturer.

# `list_manufacturers_for_supplier`

```elixir
@spec list_manufacturers_for_supplier(Ecto.UUID.t()) :: [
  PhoenixKitCatalogue.Schemas.Manufacturer.t()
]
```

Lists all manufacturers linked to a supplier, ordered by name.

# `list_suppliers_for_manufacturer`

```elixir
@spec list_suppliers_for_manufacturer(Ecto.UUID.t()) :: [
  PhoenixKitCatalogue.Schemas.Supplier.t()
]
```

Lists all suppliers linked to a manufacturer, ordered by name.

# `sync_manufacturer_suppliers`

```elixir
@spec sync_manufacturer_suppliers(Ecto.UUID.t(), [Ecto.UUID.t()], keyword()) ::
  {:ok, :synced} | {:error, term()}
```

Syncs the supplier links for a manufacturer to match the given list of supplier UUIDs.

Adds missing links and removes extra ones via set difference.
Returns `{:ok, :synced}` on success or `{:error, reason}` on the first failure.

# `sync_supplier_manufacturers`

```elixir
@spec sync_supplier_manufacturers(Ecto.UUID.t(), [Ecto.UUID.t()], keyword()) ::
  {:ok, :synced} | {:error, term()}
```

Syncs the manufacturer links for a supplier to match the given list of manufacturer UUIDs.

Adds missing links and removes extra ones via set difference.
Returns `{:ok, :synced}` on success or `{:error, reason}` on the first failure.

# `unlink_manufacturer_supplier`

```elixir
@spec unlink_manufacturer_supplier(Ecto.UUID.t(), Ecto.UUID.t()) ::
  {:ok, PhoenixKitCatalogue.Schemas.ManufacturerSupplier.t()}
  | {:error,
     :not_found
     | Ecto.Changeset.t(PhoenixKitCatalogue.Schemas.ManufacturerSupplier.t())}
```

Removes the link between a manufacturer and a supplier.

Returns `{:error, :not_found}` if the link doesn't exist.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
