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

namespace ERPCore.Dtos.Hrm;

public sealed record EmployeeListItemDto(
    int EmployeeId, string EmployeeCode, string FullName, string? Email,
    int DepartmentId, string? DepartmentName, int DesignationId, string? DesignationName,
    int EmploymentTypeId, string? EmploymentTypeName, int? BranchId, string? BranchName,
    EmployeeStatus Status, bool HasUserLink, DateTime HireDate);

public sealed record EmployeeDetailDto(
    int EmployeeId, string EmployeeCode, string FullName, string? Nic, DateTime? DateOfBirth,
    Gender? Gender, string? Nationality, string? ProfilePhotoPath,
    string? Email, string? PersonalMobile, string? AddressLine1, string? AddressLine2,
    string? City, string? PostalCode, string? Country,
    string? EmergencyContactName, string? EmergencyContactRelationship, string? EmergencyContactPhone,
    DateTime HireDate, DateTime? ConfirmationDate, DateTime? LastWorkingDate,
    int DepartmentId, int DesignationId, int EmploymentTypeId, int? BranchId, int WorkShiftId,
    int? ReportingManagerId, string? EpfNumber, string? EtfNumber, string? TaxIdentificationNumber,
    int? UserId, EmployeeStatus Status, DateTime CreatedAt, DateTime? UpdatedAt);

public sealed class CreateEmployeeRequest
{
    [Required, StringLength(30)] public string EmployeeCode { get; set; } = string.Empty;
    [Required, StringLength(200)] public string FullName { get; set; } = string.Empty;
    [StringLength(30)] public string? Nic { get; set; }
    public DateTime? DateOfBirth { get; set; }
    public Gender? Gender { get; set; }
    [StringLength(100)] public string? Nationality { get; set; }

    [EmailAddress, StringLength(320)] public string? Email { get; set; }
    [StringLength(30)] public string? PersonalMobile { get; set; }
    [StringLength(200)] public string? AddressLine1 { get; set; }
    [StringLength(200)] public string? AddressLine2 { get; set; }
    [StringLength(100)] public string? City { get; set; }
    [StringLength(20)] public string? PostalCode { get; set; }
    [StringLength(100)] public string? Country { get; set; }

    [StringLength(200)] public string? EmergencyContactName { get; set; }
    [StringLength(100)] public string? EmergencyContactRelationship { get; set; }
    [StringLength(30)] public string? EmergencyContactPhone { get; set; }

    [Required] public DateTime HireDate { get; set; }
    [Required] public int DepartmentId { get; set; }
    [Required] public int DesignationId { get; set; }
    [Required] public int EmploymentTypeId { get; set; }
    public int? BranchId { get; set; }
    [Required] public int WorkShiftId { get; set; }
    public int? ReportingManagerId { get; set; }

    [StringLength(30)] public string? EpfNumber { get; set; }
    [StringLength(30)] public string? EtfNumber { get; set; }
    [StringLength(30)] public string? TaxIdentificationNumber { get; set; }

    /// <summary>Explicit, human-confirmed link to an existing User found via email-lookup — never automatic.</summary>
    public int? LinkUserId { get; set; }
}

public sealed class UpdateEmployeeRequest
{
    [Required, StringLength(200)] public string FullName { get; set; } = string.Empty;
    [StringLength(30)] public string? Nic { get; set; }
    public DateTime? DateOfBirth { get; set; }
    public Gender? Gender { get; set; }
    [StringLength(100)] public string? Nationality { get; set; }

    [EmailAddress, StringLength(320)] public string? Email { get; set; }
    [StringLength(30)] public string? PersonalMobile { get; set; }
    [StringLength(200)] public string? AddressLine1 { get; set; }
    [StringLength(200)] public string? AddressLine2 { get; set; }
    [StringLength(100)] public string? City { get; set; }
    [StringLength(20)] public string? PostalCode { get; set; }
    [StringLength(100)] public string? Country { get; set; }

    [StringLength(200)] public string? EmergencyContactName { get; set; }
    [StringLength(100)] public string? EmergencyContactRelationship { get; set; }
    [StringLength(30)] public string? EmergencyContactPhone { get; set; }

    public DateTime? ConfirmationDate { get; set; }
    public DateTime? LastWorkingDate { get; set; }
    [Required] public int DepartmentId { get; set; }
    [Required] public int DesignationId { get; set; }
    [Required] public int EmploymentTypeId { get; set; }
    public int? BranchId { get; set; }
    [Required] public int WorkShiftId { get; set; }
    public int? ReportingManagerId { get; set; }

    [StringLength(30)] public string? EpfNumber { get; set; }
    [StringLength(30)] public string? EtfNumber { get; set; }
    [StringLength(30)] public string? TaxIdentificationNumber { get; set; }
}

public sealed class UpdateEmployeeStatusRequest
{
    [Required, EnumDataType(typeof(EmployeeStatus))] public EmployeeStatus Status { get; set; }
}

public sealed record EmployeeBankDetailDto(
    int EmployeeBankDetailId, string BankName, string BranchName, string AccountNumber,
    string AccountHolderName, string? SwiftCode, bool IsPrimary, EntityStatus Status);

public sealed class UpsertEmployeeBankDetailRequest
{
    public int? EmployeeBankDetailId { get; set; }
    [Required, StringLength(200)] public string BankName { get; set; } = string.Empty;
    [Required, StringLength(200)] public string BranchName { get; set; } = string.Empty;
    [Required, StringLength(50)] public string AccountNumber { get; set; } = string.Empty;
    [Required, StringLength(200)] public string AccountHolderName { get; set; } = string.Empty;
    [StringLength(20)] public string? SwiftCode { get; set; }
    public bool IsPrimary { get; set; }
}

public sealed class ReplaceEmployeeBankDetailsRequest
{
    [Required] public List<UpsertEmployeeBankDetailRequest> Items { get; set; } = new();
}
