using System.ComponentModel.DataAnnotations;
using ERPCore.Domain.Enums;

namespace ERPCore.Dtos.Hrm;

public sealed record LeaveTypeDto(
    int LeaveTypeId, string Code, string Name, bool IsPaid, bool CountsAsNoPay, decimal AccrualPerYear,
    bool CarryForwardAllowed, int? MaxCarryForwardDays, bool RequiresApproval, EntityStatus Status,
    DateTime CreatedAt, DateTime? UpdatedAt);

public sealed class CreateLeaveTypeRequest
{
    [Required, StringLength(20)] public string Code { get; set; } = string.Empty;
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
    public bool IsPaid { get; set; } = true;
    public bool CountsAsNoPay { get; set; }
    [Range(0, 365)] public decimal AccrualPerYear { get; set; }
    public bool CarryForwardAllowed { get; set; }
    public int? MaxCarryForwardDays { get; set; }
    public bool RequiresApproval { get; set; } = true;
}

public sealed class UpdateLeaveTypeRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
    public bool IsPaid { get; set; }
    public bool CountsAsNoPay { get; set; }
    [Range(0, 365)] public decimal AccrualPerYear { get; set; }
    public bool CarryForwardAllowed { get; set; }
    public int? MaxCarryForwardDays { get; set; }
    public bool RequiresApproval { get; set; }
}

public sealed record LeaveRequestDto(
    int LeaveRequestId, string DocNo, int EmployeeId, string? EmployeeName, int LeaveTypeId, string? LeaveTypeName,
    DateTime StartDate, DateTime EndDate, decimal DaysCount, string? Reason,
    LeaveRequestStatus Status, int? ApprovedBy, DateTime? ApprovedAt, string? RejectionReason, DateTime CreatedAt);

public sealed class CreateLeaveRequestRequest
{
    [Required] public int EmployeeId { get; set; }
    [Required] public int LeaveTypeId { get; set; }
    [Required] public DateTime StartDate { get; set; }
    [Required] public DateTime EndDate { get; set; }
    [StringLength(1000)] public string? Reason { get; set; }
}

public sealed class RejectLeaveRequestRequest
{
    [Required, StringLength(1000)] public string Reason { get; set; } = string.Empty;
}

public sealed record LeaveBalanceDto(
    int LeaveBalanceId, int EmployeeId, int LeaveTypeId, string? LeaveTypeName, int Year,
    decimal EntitledDays, decimal TakenDays, decimal CarriedForwardDays, decimal AdjustmentDays, decimal RemainingDays);

public sealed class LeaveBalanceAdjustmentItem
{
    [Required] public int LeaveTypeId { get; set; }
    public decimal AdjustmentDays { get; set; }
}

public sealed class UpdateLeaveBalancesRequest
{
    [Required] public int Year { get; set; }
    [Required] public List<LeaveBalanceAdjustmentItem> Items { get; set; } = new();
}
