namespace EntKube.SharedKernel.Domain;

/// <summary>
/// A Result represents the outcome of an operation that can either succeed or fail.
/// Instead of throwing exceptions for expected failure scenarios (validation errors,
/// business rule violations, external service failures), we return a Result that
/// the caller can inspect and handle gracefully.
/// </summary>
public class Result
{
    public bool IsSuccess { get; }
    public string? Error { get; }
    public bool IsFailure => !IsSuccess;

    protected Result(bool isSuccess, string? error)
    {
        IsSuccess = isSuccess;
        Error = error;
    }

    public static Result Success() => new(true, null);

    public static Result Failure(string error) => new(false, error);

    public static Result<T> Success<T>(T value) => new(value, true, null);

    public static Result<T> Failure<T>(string error) => new(default, false, error);
}

/// <summary>
/// A typed Result that carries a value on success. When the operation succeeds,
/// the Value property contains the result. When it fails, Error describes what went wrong.
/// </summary>
public class Result<T> : Result
{
    public T? Value { get; }

    internal Result(T? value, bool isSuccess, string? error)
        : base(isSuccess, error)
    {
        Value = value;
    }
}
