using GameList.Domain; namespace GameList.Endpoints; internal enum ServiceErrorCode { BadRequest, Unauthorized, NotFound, Conflict } internal sealed record ServiceError(ServiceErrorCode Code, string Detail) { public static ServiceError BadRequest(string detail) => new(ServiceErrorCode.BadRequest, detail); public static ServiceError Unauthorized(string detail = "Unauthorized") => new(ServiceErrorCode.Unauthorized, detail); public static ServiceError NotFound(string detail) => new(ServiceErrorCode.NotFound, detail); public static ServiceError Conflict(string detail) => new(ServiceErrorCode.Conflict, detail); public static ServiceError PhaseMismatch(Phase required, Phase current) => BadRequest($"This endpoint is available in the {required} phase. Your current phase is {current}."); } internal readonly record struct Unit; internal readonly record struct ServiceResult(T? Value, ServiceError? Error) { public bool IsSuccess => Error is null; public static ServiceResult Success(T value) => new(value, null); public static ServiceResult Failure(ServiceError error) => new(default, error); }