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

namespace ERPCore.Dtos.Hrm;

// Narrow DTOs for the five HRM org masters — server-controlled fields (status,
// ids, timestamps) excluded from create/update requests (02-SECURITY B.6/C.1).

public sealed record BranchDto(
    int BranchId, string Code, string Name, string? Address, EntityStatus Status,
    DateTime CreatedAt, DateTime? UpdatedAt);

public sealed class CreateBranchRequest
{
    [Required, StringLength(20)] public string Code { get; set; } = string.Empty;
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
    [StringLength(500)] public string? Address { get; set; }
}

public sealed class UpdateBranchRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
    [StringLength(500)] public string? Address { get; set; }
}

public sealed record DepartmentDto(
    int DepartmentId, string Code, string Name, int? ParentDepartmentId, int? HeadEmployeeId,
    int? BranchId, EntityStatus Status, DateTime CreatedAt, DateTime? UpdatedAt);

public sealed class CreateDepartmentRequest
{
    [Required, StringLength(20)] public string Code { get; set; } = string.Empty;
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
    public int? ParentDepartmentId { get; set; }
    public int? HeadEmployeeId { get; set; }
    public int? BranchId { get; set; }
}

public sealed class UpdateDepartmentRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
    public int? ParentDepartmentId { get; set; }
    public int? HeadEmployeeId { get; set; }
    public int? BranchId { get; set; }
}

public sealed record DesignationDto(
    int DesignationId, string Code, string Name, EntityStatus Status, DateTime CreatedAt, DateTime? UpdatedAt);

public sealed class CreateDesignationRequest
{
    [Required, StringLength(20)] public string Code { get; set; } = string.Empty;
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
}

public sealed class UpdateDesignationRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
}

public sealed record EmploymentTypeDto(
    int EmploymentTypeId, string Code, string Name, EntityStatus Status, DateTime CreatedAt, DateTime? UpdatedAt);

public sealed class CreateEmploymentTypeRequest
{
    [Required, StringLength(20)] public string Code { get; set; } = string.Empty;
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
}

public sealed class UpdateEmploymentTypeRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
}

public sealed record WorkShiftDto(
    int WorkShiftId, string Code, string Name, TimeSpan StartTime, TimeSpan EndTime, bool IsOvernight,
    int GraceMinutes, int BreakMinutes, int StandardWorkingMinutes, decimal OtMultiplier, int WorkingDaysMask,
    EntityStatus Status, DateTime CreatedAt, DateTime? UpdatedAt);

public sealed class CreateWorkShiftRequest
{
    [Required, StringLength(20)] public string Code { get; set; } = string.Empty;
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
    [Required] public TimeSpan StartTime { get; set; }
    [Required] public TimeSpan EndTime { get; set; }
    public bool IsOvernight { get; set; }
    [Range(0, 240)] public int GraceMinutes { get; set; } = 15;
    [Range(0, 240)] public int BreakMinutes { get; set; } = 60;
    [Range(1, 1440)] public int StandardWorkingMinutes { get; set; } = 480;
    [Range(1, 5)] public decimal OtMultiplier { get; set; } = 1.5m;
    [Range(0, 127)] public int WorkingDaysMask { get; set; } = 0b0111111;
}

public sealed class UpdateWorkShiftRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
    [Required] public TimeSpan StartTime { get; set; }
    [Required] public TimeSpan EndTime { get; set; }
    public bool IsOvernight { get; set; }
    [Range(0, 240)] public int GraceMinutes { get; set; }
    [Range(0, 240)] public int BreakMinutes { get; set; }
    [Range(1, 1440)] public int StandardWorkingMinutes { get; set; }
    [Range(1, 5)] public decimal OtMultiplier { get; set; }
    [Range(0, 127)] public int WorkingDaysMask { get; set; }
}

/// <summary>Shared by all five masters' PATCH .../status endpoints.</summary>
public sealed class UpdateHrMasterStatusRequest
{
    [Required, EnumDataType(typeof(EntityStatus))] public EntityStatus Status { get; set; }
}
