using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

/// <summary>
/// Staff record (FR-HR-MD-02) — distinct from <see cref="User"/> (the system login
/// account): not every employee has a login, and not every login belongs to an
/// employee. <see cref="UserId"/> is the optional, explicit, human-confirmed link
/// between the two (docs/12-BACKEND-HRM.md A.5/C.2, Part B.3.2). Never hard-deleted —
/// separation is recorded via <see cref="Status"/> + <see cref="LastWorkingDate"/>.
/// <see cref="EmployeeCode"/> is user-entered (not <see cref="NumberSequence"/>-issued):
/// HR departments keep their own legacy numbering scheme, and NumberSequence's
/// year-scoping is the wrong shape for an identifier that must never look "reset".
/// </summary>
public class Employee
{
    public int EmployeeId { get; set; }
    public string EmployeeCode { get; set; } = string.Empty;

    // Identity
    public string FullName { get; set; } = string.Empty;
    public string? Nic { get; set; }
    public DateTime? DateOfBirth { get; set; }
    public Gender? Gender { get; set; }
    public string? Nationality { get; set; }
    public string? ProfilePhotoPath { get; set; }

    // Contact
    /// <summary>The field used for the bidirectional Employee&lt;-&gt;User email cross-check.</summary>
    public string? Email { get; set; }
    public string? PersonalMobile { get; set; }
    public string? AddressLine1 { get; set; }
    public string? AddressLine2 { get; set; }
    public string? City { get; set; }
    public string? PostalCode { get; set; }
    public string? Country { get; set; }

    // Emergency contact
    public string? EmergencyContactName { get; set; }
    public string? EmergencyContactRelationship { get; set; }
    public string? EmergencyContactPhone { get; set; }

    // Employment
    public DateTime HireDate { get; set; }
    public DateTime? ConfirmationDate { get; set; }
    public DateTime? LastWorkingDate { get; set; }
    public int DepartmentId { get; set; }
    public Department? Department { get; set; }
    public int DesignationId { get; set; }
    public Designation? Designation { get; set; }
    public int EmploymentTypeId { get; set; }
    public EmploymentType? EmploymentType { get; set; }
    public int? BranchId { get; set; }
    public Branch? Branch { get; set; }
    public int WorkShiftId { get; set; }
    public WorkShift? WorkShift { get; set; }
    public int? ReportingManagerId { get; set; }
    public Employee? ReportingManager { get; set; }

    // Statutory (Sri Lanka)
    public string? EpfNumber { get; set; }
    public string? EtfNumber { get; set; }
    public string? TaxIdentificationNumber { get; set; }

    /// <summary>Optional login account link (unique — one User backs at most one Employee).</summary>
    public int? UserId { get; set; }
    public User? User { get; set; }

    public EmployeeStatus Status { get; set; } = EmployeeStatus.Active;

    public int CreatedBy { get; set; }
    public DateTime CreatedAt { get; set; }
    public int? UpdatedBy { get; set; }
    public DateTime? UpdatedAt { get; set; }
    public uint RowVersion { get; set; }
}
