namespace ERPCore.Common.Models;

/// <summary>
/// Lightweight success/failure envelope for service-layer results where an
/// exception would be overkill. Domain errors that must reach the client as
/// RFC 7807 ProblemDetails should throw a DomainException instead
/// (see System/Errors).
/// </summary>
public readonly struct Result<T>
{
    public bool IsSuccess { get; }
    public T? Value { get; }
    public string? ErrorCode { get; }
    public string? ErrorMessage { get; }

    private Result(bool ok, T? value, string? code, string? message)
    {
        IsSuccess = ok;
        Value = value;
        ErrorCode = code;
        ErrorMessage = message;
    }

    public static Result<T> Success(T value) => new(true, value, null, null);
    public static Result<T> Failure(string code, string message) => new(false, default, code, message);
}
