using System.ComponentModel.DataAnnotations;
using PlotLine.Models;

namespace PlotLine.ViewModels;

public sealed class ManageAccountViewModel
{
    public AppUser User { get; set; } = new();
    public UserSubscriptionDetail? Subscription { get; set; }
}

public sealed class RegisterViewModel
{
    [Required(ErrorMessage = "Enter your email address.")]
    [EmailAddress(ErrorMessage = "Enter a valid email address.")]
    [StringLength(256, ErrorMessage = "Email must be 256 characters or fewer.")]
    public string Email { get; set; } = string.Empty;

    [Required(ErrorMessage = "Enter a display name.")]
    [StringLength(200, ErrorMessage = "Display name must be 200 characters or fewer.")]
    public string DisplayName { get; set; } = string.Empty;

    [Required(ErrorMessage = "Enter a password.")]
    [StringLength(200, MinimumLength = 12, ErrorMessage = "Password must be at least 12 characters.")]
    [DataType(DataType.Password)]
    public string Password { get; set; } = string.Empty;

    [Required(ErrorMessage = "Confirm your password.")]
    [DataType(DataType.Password)]
    [Compare(nameof(Password), ErrorMessage = "Passwords do not match.")]
    public string ConfirmPassword { get; set; } = string.Empty;
}

public sealed class LoginViewModel
{
    [Required(ErrorMessage = "Enter your email address.")]
    [EmailAddress(ErrorMessage = "Enter a valid email address.")]
    [StringLength(256, ErrorMessage = "Email must be 256 characters or fewer.")]
    public string Email { get; set; } = string.Empty;

    [Required(ErrorMessage = "Enter your password.")]
    [DataType(DataType.Password)]
    public string Password { get; set; } = string.Empty;

    public bool RememberMe { get; set; }

    public string? ReturnUrl { get; set; }
}

public sealed class ForgotPasswordViewModel
{
    [Required(ErrorMessage = "Enter your email address.")]
    [EmailAddress(ErrorMessage = "Enter a valid email address.")]
    [StringLength(256, ErrorMessage = "Email must be 256 characters or fewer.")]
    public string Email { get; set; } = string.Empty;
}

public sealed class ResendVerificationEmailViewModel
{
    [Required(ErrorMessage = "Enter your email address.")]
    [EmailAddress(ErrorMessage = "Enter a valid email address.")]
    [StringLength(256, ErrorMessage = "Email must be 256 characters or fewer.")]
    public string Email { get; set; } = string.Empty;
}

public sealed class ResetPasswordViewModel
{
    [Required(ErrorMessage = "Password reset token is missing.")]
    public Guid Token { get; set; }

    [Required(ErrorMessage = "Enter a new password.")]
    [StringLength(200, MinimumLength = 12, ErrorMessage = "Password must be at least 12 characters.")]
    [DataType(DataType.Password)]
    public string Password { get; set; } = string.Empty;

    [Required(ErrorMessage = "Confirm your new password.")]
    [DataType(DataType.Password)]
    [Compare(nameof(Password), ErrorMessage = "Passwords do not match.")]
    public string ConfirmPassword { get; set; } = string.Empty;
}

public sealed class AccountStatusViewModel
{
    public bool Success { get; set; }
    public string Title { get; set; } = string.Empty;
    public string Message { get; set; } = string.Empty;
}

public sealed class TwoFactorCodeViewModel
{
    [Required(ErrorMessage = "Enter the code from your authenticator app.")]
    [StringLength(20, ErrorMessage = "Authentication code is too long.")]
    public string Code { get; set; } = string.Empty;

    public string? ReturnUrl { get; set; }
}

public sealed class TwoFactorRecoveryViewModel
{
    [Required(ErrorMessage = "Enter a recovery code.")]
    [StringLength(20, ErrorMessage = "Recovery code is too long.")]
    public string RecoveryCode { get; set; } = string.Empty;

    public string? ReturnUrl { get; set; }
}

public sealed class EnableTwoFactorViewModel
{
    [Required(ErrorMessage = "Authenticator secret is missing.")]
    public string SecretKey { get; set; } = string.Empty;

    public string QrCodeUri { get; set; } = string.Empty;

    public string? QrCodeImageDataUri { get; set; }

    [Required(ErrorMessage = "Enter the code from your authenticator app.")]
    [StringLength(20, ErrorMessage = "Authentication code is too long.")]
    public string Code { get; set; } = string.Empty;
}

public sealed class DisableTwoFactorViewModel
{
    [Required(ErrorMessage = "Enter your current password.")]
    [DataType(DataType.Password)]
    public string CurrentPassword { get; set; } = string.Empty;
}

public sealed class RecoveryCodesViewModel
{
    public IReadOnlyList<string> RecoveryCodes { get; set; } = Array.Empty<string>();
    public bool HasNewCodes => RecoveryCodes.Any();
}

public sealed class ChangePasswordViewModel
{
    [Required(ErrorMessage = "Enter your current password.")]
    [DataType(DataType.Password)]
    public string CurrentPassword { get; set; } = string.Empty;

    [Required(ErrorMessage = "Enter a new password.")]
    [StringLength(200, MinimumLength = 12, ErrorMessage = "Password must be at least 12 characters.")]
    [DataType(DataType.Password)]
    public string NewPassword { get; set; } = string.Empty;

    [Required(ErrorMessage = "Confirm your new password.")]
    [DataType(DataType.Password)]
    [Compare(nameof(NewPassword), ErrorMessage = "Passwords do not match.")]
    public string ConfirmNewPassword { get; set; } = string.Empty;
}
