
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;

namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests.MobileApp;

public class MobileAppAuthRequest : AuthLoginRequest
{

}

public class AuthLogoutRequest
{
    [Required, NotNull, StringLength(maximumLength: 10, MinimumLength = 3, ErrorMessage = "Login Id must be between 3 and 10 characters.")]
    public string LoginId { get; set; }
}


public class AppUserChangePasswordRequest
{
    [Required, NotNull, StringLength(maximumLength: 10, MinimumLength = 3, ErrorMessage = "Login Id must be between 3 and 10 characters.")]
    public string LoginId { get; set; }

    [Required, NotNull, StringLength(maximumLength: 20, MinimumLength = 5, ErrorMessage = "Password must be between 5 and 20 characters.")]
    public string Password { get; set; }

    [Required, NotNull, StringLength(maximumLength: 20, MinimumLength = 5, ErrorMessage = "Password must be between 5 and 20 characters.")]
    public string NewPassword { get; set; }

    [Required, NotNull, StringLength(maximumLength: 20, MinimumLength = 5, ErrorMessage = "Password must be between 5 and 20 characters.")]
    [Compare("NewPassword", ErrorMessage = "Password and Confirm Password do not match.")]
    public string ConfirmPassword { get; set; }

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        if (!string.IsNullOrWhiteSpace(NewPassword) &&
            !string.IsNullOrWhiteSpace(ConfirmPassword) &&
            Password != ConfirmPassword)
        {
            yield return new ValidationResult(
                "Password and Confirm Password do not match.",
                [nameof(NewPassword), nameof(ConfirmPassword)]
            );
        }

        if (!string.IsNullOrWhiteSpace(LoginId) &&
            !string.IsNullOrWhiteSpace(NewPassword) &&
            Password.Equals(LoginId, StringComparison.OrdinalIgnoreCase))
        {
            yield return new ValidationResult(
                "Password must not be the same as your Login ID.",
                [nameof(NewPassword)]
            );
        }
    }

}

