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

namespace ERPCore.Dtos.Hrm;

public sealed record AttendanceUploadBatchDto(
    int AttendanceUploadBatchId, string DocNo, DateTime PeriodStart, DateTime PeriodEnd,
    AttendanceSourceType SourceType, string? OriginalFileName, int UploadedBy, DateTime UploadedAt,
    AttendanceBatchStatus Status, int? ConfirmedBy, DateTime? ConfirmedAt,
    int RowCountTotal, int RowCountDuplicate, int RowCountError);

public sealed class UploadAttendanceBatchMetadata
{
    [Required] public DateTime PeriodStart { get; set; }
    [Required] public DateTime PeriodEnd { get; set; }
}

public sealed record AttendanceRecordDto(
    int AttendanceRecordId, int? AttendanceUploadBatchId, int EmployeeId, string? EmployeeCode, string? EmployeeName,
    DateTime AttendanceDate, TimeSpan? CheckIn, TimeSpan? CheckOut,
    int WorkingMinutes, int LateMinutes, int EarlyLeaveMinutes, int OvertimeMinutes,
    AttendanceStatus AttendanceStatus, RowValidationStatus RowValidationStatus,
    int? DuplicateOfAttendanceRecordId, string? Notes);

public sealed class UpdateAttendanceRecordRequest
{
    public TimeSpan? CheckIn { get; set; }
    public TimeSpan? CheckOut { get; set; }
    public AttendanceStatus? AttendanceStatus { get; set; }
    [StringLength(1000)] public string? Notes { get; set; }
}

public sealed class ResolveDuplicateRequest
{
    [Required] public int RecordId { get; set; }
    /// <summary>"keep" discards the other duplicate row(s); "discard" removes this row; "supersede" (cross-batch-confirmed only) replaces the prior confirmed record.</summary>
    [Required, RegularExpression("^(keep|discard|supersede)$")]
    public string Action { get; set; } = string.Empty;
}

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