using System.ComponentModel.DataAnnotations;
using MilitaryTrainingManagement.Models.Enums;

namespace MilitaryTrainingManagement.Models.DTOs;

/// <summary>
/// 创建人员请求DTO
/// </summary>
public class CreatePersonnelRequest
{
    [Required(ErrorMessage = "姓名不能为空")]
    [StringLength(50, MinimumLength = 2, ErrorMessage = "姓名长度应在2-50个字符之间")]
    public string Name { get; set; } = string.Empty;

    [StringLength(100, ErrorMessage = "单位长度不能超过100个字符")]
    public string? Unit { get; set; }

    [Required(ErrorMessage = "职位不能为空")]
    [StringLength(100, ErrorMessage = "职位长度不能超过100个字符")]
    public string Position { get; set; } = string.Empty;

    [Required(ErrorMessage = "军衔不能为空")]
    [StringLength(50, ErrorMessage = "军衔长度不能超过50个字符")]
    public string Rank { get; set; } = string.Empty;

    [StringLength(50, ErrorMessage = "士兵证号长度不能超过50个字符")]
    public string? IdNumber { get; set; }

    [StringLength(100, ErrorMessage = "专业岗位长度不能超过100个字符")]
    public string? ProfessionalTitle { get; set; }

    [StringLength(50, ErrorMessage = "文化程度长度不能超过50个字符")]
    public string? EducationLevel { get; set; }

    [StringLength(50, ErrorMessage = "民族长度不能超过50个字符")]
    public string? Ethnicity { get; set; }

    [StringLength(50, ErrorMessage = "政治面貌长度不能超过50个字符")]
    public string? PoliticalStatus { get; set; }

    [StringLength(20, ErrorMessage = "出生年月格式不正确")]
    public string? BirthDate { get; set; }

    [StringLength(20, ErrorMessage = "入伍年月格式不正确")]
    public string? EnlistmentDate { get; set; }

    [StringLength(200, ErrorMessage = "籍贯长度不能超过200个字符")]
    public string? Hometown { get; set; }

    [StringLength(200, ErrorMessage = "特长长度不能超过200个字符")]
    public string? Specialty { get; set; }

    [StringLength(1000, ErrorMessage = "参加培训、集训情况长度不能超过1000个字符")]
    public string? TrainingParticipation { get; set; }

    [StringLength(1000, ErrorMessage = "取得成绩长度不能超过1000个字符")]
    public string? Achievements { get; set; }
}

/// <summary>
/// 更新人员请求DTO
/// </summary>
public class UpdatePersonnelRequest
{
    [Required(ErrorMessage = "姓名不能为空")]
    [StringLength(50, MinimumLength = 2, ErrorMessage = "姓名长度应在2-50个字符之间")]
    public string Name { get; set; } = string.Empty;

    [Required(ErrorMessage = "职位不能为空")]
    [StringLength(100, ErrorMessage = "职位长度不能超过100个字符")]
    public string Position { get; set; } = string.Empty;

    [Required(ErrorMessage = "军衔不能为空")]
    [StringLength(50, ErrorMessage = "军衔长度不能超过50个字符")]
    public string Rank { get; set; } = string.Empty;

    [Required(ErrorMessage = "性别不能为空")]
    [RegularExpression("^(男|女)$", ErrorMessage = "性别必须是'男'或'女'")]
    public string Gender { get; set; } = string.Empty;

    [StringLength(100, ErrorMessage = "专业职位长度不能超过100个字符")]
    public string? ProfessionalTitle { get; set; }

    [StringLength(50, ErrorMessage = "文化程度长度不能超过50个字符")]
    public string? EducationLevel { get; set; }

    [Required(ErrorMessage = "年龄不能为空")]
    [Range(18, 60, ErrorMessage = "年龄应在18-60岁之间")]
    public int Age { get; set; }

    [Range(140, 220, ErrorMessage = "身高应在140-220厘米之间")]
    public decimal? Height { get; set; }

    [StringLength(100, ErrorMessage = "联系方式长度不能超过100个字符")]
    public string? ContactInfo { get; set; }

    [StringLength(200, ErrorMessage = "籍贯长度不能超过200个字符")]
    public string? Hometown { get; set; }

    [StringLength(1000, ErrorMessage = "参加培训情况长度不能超过1000个字符")]
    public string? TrainingParticipation { get; set; }

    [StringLength(1000, ErrorMessage = "取得成绩长度不能超过1000个字符")]
    public string? Achievements { get; set; }
}

/// <summary>
/// 审批人员请求DTO
/// </summary>
public class ApprovePersonnelRequest
{
    [Required(ErrorMessage = "人员等级不能为空")]
    public PersonnelLevel Level { get; set; }
}

/// <summary>
/// 拒绝人员请求DTO
/// </summary>
public class RejectPersonnelRequest
{
    [StringLength(500, ErrorMessage = "拒绝原因长度不能超过500个字符")]
    public string? Reason { get; set; }
}

/// <summary>
/// 拒绝向上申报请求DTO
/// </summary>
public class RejectUpgradeRequest
{
    [Required(ErrorMessage = "拒绝原因不能为空")]
    [StringLength(500, ErrorMessage = "拒绝原因长度不能超过500个字符")]
    public string Comments { get; set; } = string.Empty;
}

/// <summary>
/// 人员响应DTO
/// </summary>
public class PersonnelResponse
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public string? PhotoPath { get; set; }
    public string? Unit { get; set; }
    public string Position { get; set; } = string.Empty;
    public string Rank { get; set; } = string.Empty;
    public string Gender { get; set; } = string.Empty;
    public string? IdNumber { get; set; }
    public string? ProfessionalTitle { get; set; }
    public string? EducationLevel { get; set; }
    public int Age { get; set; }
    public decimal? Height { get; set; }
    public string? ContactInfo { get; set; }
    public string? Hometown { get; set; }
    public string? TrainingParticipation { get; set; }
    public string? Achievements { get; set; }
    public string? SupportingDocuments { get; set; }
    
    // 新增字段
    public string? Ethnicity { get; set; }
    public string? PoliticalStatus { get; set; }
    public string? BirthDate { get; set; }
    public string? EnlistmentDate { get; set; }
    public string? Specialty { get; set; }
    
    public int SubmittedByUnitId { get; set; }
    public string? SubmittedByUnitName { get; set; }
    public PersonnelLevel? ApprovedLevel { get; set; }
    public int? ApprovedByUnitId { get; set; }
    public string? ApprovedByUnitName { get; set; }
    public PersonnelStatus Status { get; set; }
    public DateTime SubmittedAt { get; set; }
    public DateTime? ApprovedAt { get; set; }
    public int? PendingUpgradeByUnitId { get; set; } // 待向上申报的申报单位ID
}

/// <summary>
/// 人员列表响应DTO
/// </summary>
public class PersonnelListResponse
{
    public IEnumerable<PersonnelResponse> Items { get; set; } = new List<PersonnelResponse>();
    public int TotalCount { get; set; }
}

/// <summary>
/// 提交人员请求DTO（包含文件上传）
/// </summary>
public class SubmitPersonnelRequest
{
    [Required(ErrorMessage = "姓名不能为空")]
    [StringLength(50, MinimumLength = 2, ErrorMessage = "姓名长度应在2-50个字符之间")]
    public string Name { get; set; } = string.Empty;

    [StringLength(100, ErrorMessage = "单位长度不能超过100个字符")]
    public string? Unit { get; set; }

    [Required(ErrorMessage = "职位不能为空")]
    [StringLength(100, ErrorMessage = "职位长度不能超过100个字符")]
    public string Position { get; set; } = string.Empty;

    [Required(ErrorMessage = "军衔不能为空")]
    [StringLength(50, ErrorMessage = "军衔长度不能超过50个字符")]
    public string Rank { get; set; } = string.Empty;

    [StringLength(50, ErrorMessage = "士兵证号长度不能超过50个字符")]
    public string? IdNumber { get; set; }

    [StringLength(100, ErrorMessage = "专业岗位长度不能超过100个字符")]
    public string? ProfessionalTitle { get; set; }

    [StringLength(50, ErrorMessage = "文化程度长度不能超过50个字符")]
    public string? EducationLevel { get; set; }

    [StringLength(50, ErrorMessage = "民族长度不能超过50个字符")]
    public string? Ethnicity { get; set; }

    [StringLength(50, ErrorMessage = "政治面貌长度不能超过50个字符")]
    public string? PoliticalStatus { get; set; }

    [StringLength(20, ErrorMessage = "出生年月格式不正确")]
    public string? BirthDate { get; set; }

    [StringLength(20, ErrorMessage = "入伍年月格式不正确")]
    public string? EnlistmentDate { get; set; }

    [StringLength(200, ErrorMessage = "籍贯长度不能超过200个字符")]
    public string? Hometown { get; set; }

    [StringLength(200, ErrorMessage = "特长长度不能超过200个字符")]
    public string? Specialty { get; set; }

    [StringLength(1000, ErrorMessage = "参加培训、集训情况长度不能超过1000个字符")]
    public string? TrainingParticipation { get; set; }

    [StringLength(1000, ErrorMessage = "取得成绩长度不能超过1000个字符")]
    public string? Achievements { get; set; }
}

/// <summary>
/// 批量审批人员请求DTO
/// </summary>
public class BatchApprovePersonnelRequest
{
    [Required(ErrorMessage = "人员ID列表不能为空")]
    public int[] PersonnelIds { get; set; } = Array.Empty<int>();

    [Required(ErrorMessage = "人员等级不能为空")]
    public PersonnelLevel Level { get; set; }
}

/// <summary>
/// 批量拒绝人员请求DTO
/// </summary>
public class BatchRejectPersonnelRequest
{
    [Required(ErrorMessage = "人员ID列表不能为空")]
    public int[] PersonnelIds { get; set; } = Array.Empty<int>();

    [Required(ErrorMessage = "拒绝原因不能为空")]
    [StringLength(500, ErrorMessage = "拒绝原因长度不能超过500个字符")]
    public string Reason { get; set; } = string.Empty;
}

/// <summary>
/// 人员转移请求DTO
/// </summary>
public class TransferPersonnelRequest
{
    [Required(ErrorMessage = "目标单位ID不能为空")]
    public int TargetUnitId { get; set; }
}

/// <summary>
/// 人员修改请求DTO
/// </summary>
public class PersonnelModificationRequest
{
    [Required(ErrorMessage = "修改原因不能为空")]
    [StringLength(500, ErrorMessage = "修改原因长度不能超过500个字符")]
    public string Reason { get; set; } = string.Empty;

    [Required(ErrorMessage = "修改的人员信息不能为空")]
    public UpdatePersonnelRequest ModifiedPersonnel { get; set; } = new();
}
