using SolutionErp.Domain.Common;

namespace SolutionErp.Domain.Office;

// Phase 10.4 G-P1 (Mig 40 — S38 2026-05-28) — Chấm công.
// Pure web GPS check-in (NO device integration per anh main chốt S32).
// Mỗi row = 1 ngày × 1 user. Composite UNIQUE (UserId, AttendanceDate).
// Monthly report aggregate query — OT calc tham chiếu Hrm_OtPolicy (Mig 35).
public class Attendance : AuditableEntity
{
    public Guid UserId { get; set; }
    public string UserFullName { get; set; } = string.Empty;  // denorm

    public DateTime AttendanceDate { get; set; }              // chỉ Date (Time=00:00)

    public DateTime? CheckInAt { get; set; }                  // UTC datetime full timestamp
    public DateTime? CheckOutAt { get; set; }

    // GPS coordinates check-in (lat, long, accuracy meters)
    public decimal? CheckInLatitude { get; set; }
    public decimal? CheckInLongitude { get; set; }
    public decimal? CheckInAccuracy { get; set; }
    public decimal? CheckOutLatitude { get; set; }
    public decimal? CheckOutLongitude { get; set; }
    public decimal? CheckOutAccuracy { get; set; }

    public AttendanceSource SourceIn { get; set; } = AttendanceSource.Web;
    public AttendanceSource SourceOut { get; set; } = AttendanceSource.Web;

    public string? IpAddressIn { get; set; }
    public string? IpAddressOut { get; set; }

    public string? Note { get; set; }                          // "Đi muộn do tắc đường"

    // Computed total work hours (decimal hours, vd 8.5 = 8h30min)
    public decimal? WorkHours { get; set; }
    public decimal? OtHours { get; set; }                      // hours beyond shift end
}

public enum AttendanceSource
{
    Web = 1,
    Mobile = 2,
    Device = 3,         // device integration future (vân tay/face recog)
}
