using BankSampahApp.Models;

namespace BankSampahApp.Services;

/// <summary>
/// Interface untuk common validation logic
/// </summary>
public interface IValidationService
{
    /// <summary>
    /// Validates statistics model
    /// </summary>
    /// <param name="statistics">Statistics to validate</param>
    /// <returns>Validation result</returns>
    ValidationResult ValidateStatistics(StatisticsModel statistics);

    /// <summary>
    /// Validates feature model
    /// </summary>
    /// <param name="feature">Feature to validate</param>
    /// <returns>Validation result</returns>
    ValidationResult ValidateFeature(FeatureModel feature);

    /// <summary>
    /// Validates date range
    /// </summary>
    /// <param name="startDate">Start date</param>
    /// <param name="endDate">End date</param>
    /// <returns>Validation result</returns>
    ValidationResult ValidateDateRange(DateTime startDate, DateTime endDate);

    /// <summary>
    /// Validates required string fields
    /// </summary>
    /// <param name="value">String value to validate</param>
    /// <param name="fieldName">Name of the field</param>
    /// <param name="maxLength">Maximum length allowed</param>
    /// <returns>Validation result</returns>
    ValidationResult ValidateRequiredString(string? value, string fieldName, int maxLength = int.MaxValue);

    /// <summary>
    /// Validates numeric range
    /// </summary>
    /// <param name="value">Numeric value to validate</param>
    /// <param name="fieldName">Name of the field</param>
    /// <param name="minValue">Minimum allowed value</param>
    /// <param name="maxValue">Maximum allowed value</param>
    /// <returns>Validation result</returns>
    ValidationResult ValidateNumericRange(decimal value, string fieldName, decimal minValue = 0, decimal maxValue = decimal.MaxValue);
}

/// <summary>
/// Result of validation operation
/// </summary>
public class ValidationResult
{
    public bool IsValid { get; set; }
    public List<string> Errors { get; set; } = new();

    public static ValidationResult Success() => new() { IsValid = true };

    public static ValidationResult Failure(string error) => new()
    {
        IsValid = false,
        Errors = new List<string> { error }
    };

    public static ValidationResult Failure(IEnumerable<string> errors) => new()
    {
        IsValid = false,
        Errors = errors.ToList()
    };
}