# Interface MaterialRepository

All Known Implementing Classes:
  `JsonMaterialRepository`, `ModernJsonMaterialRepository`

public interface MaterialRepository
Port interface for material persistence operations in hexagonal architecture. Defines the contract for material storage without specifying implementation details.

This interface represents the "port" in the ports and adapters pattern, allowing the domain layer to interact with persistence without being coupled to specific storage technologies (JSON, database, etc.).

Since:
  2024-09-15
Version:
  3.0
Author:
  Navid Mohaghegh

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `count()`
  Counts the total number of materials in the repository.
  `boolean`
  `delete(String id)`
  Deletes a material by its ID.
  `void`
  `deleteAll()`
  Deletes all materials from the repository.
  `boolean`
  `exists(String id)`
  Checks if a material with the given ID exists.
  `List<Material>`
  `findAll()`
  Retrieves all materials from the repository.
  `Optional<Material>`
  `findById(String id)`
  Finds a material by its unique identifier.
  `void`
  `save(Material material)`
  Saves a material to the repository.

- ## Method Details

  - ### save

    void save(Material material)
    Saves a material to the repository. If a material with the same ID already exists, it will be updated.
    Parameters:
      `material` - the material to save
    Throws:
      `RepositoryException` - if the save operation fails

  - ### findById

    Optional<Material> findById(String id)
    Finds a material by its unique identifier.
    Parameters:
      `id` - the material ID
    Returns:
      the material if found, empty Optional otherwise
    Throws:
      `RepositoryException` - if the find operation fails

  - ### findAll

    List<Material> findAll()
    Retrieves all materials from the repository.
    Returns:
      list of all materials
    Throws:
      `RepositoryException` - if the retrieval operation fails

  - ### delete

    boolean delete(String id)
    Deletes a material by its ID.
    Parameters:
      `id` - the material ID to delete
    Returns:
      true if the material was deleted, false if not found
    Throws:
      `RepositoryException` - if the delete operation fails

  - ### exists

    boolean exists(String id)
    Checks if a material with the given ID exists.
    Parameters:
      `id` - the material ID
    Returns:
      true if the material exists, false otherwise
    Throws:
      `RepositoryException` - if the check operation fails

  - ### count

    long count()
    Counts the total number of materials in the repository.
    Returns:
      the number of materials
    Throws:
      `RepositoryException` - if the count operation fails

  - ### deleteAll

    void deleteAll()
    Deletes all materials from the repository.
    Throws:
      `RepositoryException` - if the clear operation fails