package repository

/** Typed error ADT for repository operations
  *
  * Provides compile-time checked errors for all data access operations. Each
  * error type includes context for proper error handling and user-friendly
  * messages.
  *
  * Usage:
  * {{{
  * def findUser(id: Long): IO[RepositoryError, User] = ???
  *
  * // Handle specific error types
  * result.catchSome {
  *   case RepositoryError.NotFound(entity, id) =>
  *     ZIO.fail(HttpError.NotFound(s"$entity $id not found"))
  * }
  * }}}
  */
sealed trait RepositoryError

object RepositoryError:

  /** Entity with given ID was not found */
  case class NotFound(entity: String, id: Long) extends RepositoryError

  /** Entity with given field value was not found */
  case class NotFoundByField(entity: String, field: String, value: String)
      extends RepositoryError

  /** Operation would violate uniqueness constraint */
  case class Conflict(entity: String, message: String) extends RepositoryError

  /** Input validation failed */
  case class ValidationError(errors: List[String]) extends RepositoryError

  /** Database-level error occurred */
  case class DatabaseError(message: String, cause: Option[Throwable] = None)
      extends RepositoryError
