package com.dora.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 管理员员工管理相关DTO
 */
public class AdminEmployeeDto {

    @Data
    @Schema(description = "员工列表请求")
    public static class EmployeeListRequest {
        @Schema(description = "页码", example = "1")
        private Integer pageNum = 1;

        @Schema(description = "每页大小", example = "20")
        private Integer pageSize = 20;

        @Schema(description = "搜索关键词", example = "用户名或姓名")
        private String keyword;

        @Schema(description = "角色筛选", example = "1")
        private Integer role;

        @Schema(description = "状态筛选", example = "1")
        private Integer status;

        @Schema(description = "部门筛选", example = "技术部")
        private String department;

        @Schema(description = "排序字段", example = "create_time")
        private String sortField = "create_time";

        @Schema(description = "排序方向", example = "desc")
        private String sortOrder = "desc";
    }

    @Data
    @Schema(description = "员工列表响应")
    public static class EmployeeListResponse {
        @Schema(description = "员工列表")
        private List<EmployeeListItem> list;

        @Schema(description = "总数量")
        private Long total;

        @Schema(description = "当前页码")
        private Integer pageNum;

        @Schema(description = "每页大小")
        private Integer pageSize;
    }

    @Data
    @Schema(description = "员工列表项")
    public static class EmployeeListItem {
        @Schema(description = "员工ID")
        private Long id;

        @Schema(description = "用户名")
        private String username;

        @Schema(description = "姓名")
        private String realName;

        @Schema(description = "邮箱")
        private String email;

        @Schema(description = "手机号")
        private String phone;

        @Schema(description = "角色")
        private Integer role;

        @Schema(description = "角色名称")
        private String roleName;

        @Schema(description = "状态")
        private Integer status;

        @Schema(description = "状态名称")
        private String statusName;

        @Schema(description = "最后登录时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime lastLoginTime;

        @Schema(description = "创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime createTime;

        @Schema(description = "更新时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime updateTime;
    }

    @Data
    @Schema(description = "员工详情响应")
    public static class EmployeeDetailResponse {
        @Schema(description = "员工基本信息")
        private EmployeeDetail employeeDetail;

        @Schema(description = "操作统计")
        private EmployeeStatistics statistics;

        @Schema(description = "最近操作记录")
        private List<OperationLog> recentOperations;
    }

    @Data
    @Schema(description = "员工详细信息")
    public static class EmployeeDetail {
        @Schema(description = "员工ID")
        private Long id;

        @Schema(description = "用户名")
        private String username;

        @Schema(description = "姓名")
        private String realName;

        @Schema(description = "邮箱")
        private String email;

        @Schema(description = "手机号")
        private String phone;

        @Schema(description = "角色")
        private Integer role;

        @Schema(description = "角色名称")
        private String roleName;

        @Schema(description = "状态")
        private Integer status;

        @Schema(description = "状态名称")
        private String statusName;

        @Schema(description = "部门")
        private String department;

        @Schema(description = "职位")
        private String position;

        @Schema(description = "备注")
        private String remark;

        @Schema(description = "创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime createTime;

        @Schema(description = "更新时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime updateTime;

        @Schema(description = "最后登录时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime lastLoginTime;

        @Schema(description = "最后登录IP")
        private String lastLoginIp;
    }

    @Data
    @Schema(description = "员工统计信息")
    public static class EmployeeStatistics {
        @Schema(description = "本月登录次数")
        private Long monthlyLogins;

        @Schema(description = "本月操作次数")
        private Long monthlyOperations;

        @Schema(description = "处理的审核数量")
        private Long auditCount;

        @Schema(description = "处理的提现数量")
        private Long withdrawCount;
    }

    @Data
    @Schema(description = "操作日志")
    public static class OperationLog {
        @Schema(description = "操作类型")
        private String operationType;

        @Schema(description = "操作描述")
        private String description;

        @Schema(description = "操作时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime operationTime;

        @Schema(description = "操作IP")
        private String operationIp;
    }

    @Data
    @Schema(description = "创建员工请求")
    public static class EmployeeCreateRequest {
        @NotBlank(message = "用户名不能为空")
        @Size(min = 3, max = 20, message = "用户名长度必须在3-20个字符之间")
        @Pattern(regexp = "^[a-zA-Z0-9_]+$", message = "用户名只能包含字母、数字和下划线")
        @Schema(description = "用户名", example = "employee001")
        private String username;

        @NotBlank(message = "密码不能为空")
        @Size(min = 6, max = 20, message = "密码长度必须在6-20个字符之间")
        @Schema(description = "密码", example = "123456")
        private String password;

        @Schema(description = "密码哈希", example = "hashed_password")
        private String passwordHash;

        @Schema(description = "姓名", example = "张三")
        private String realName;

        @Schema(description = "邮箱", example = "employee@example.com")
        private String email;

        @Schema(description = "手机号", example = "13800138000")
        private String phone;

        @NotNull(message = "角色不能为空")
        @Schema(description = "角色（0普通员工/1管理员）", example = "0")
        private Integer role;

        @Schema(description = "部门", example = "技术部")
        private String department;

        @Schema(description = "职位", example = "后端开发工程师")
        private String position;

        @Schema(description = "备注")
        private String remark;
    }

    @Data
    @Schema(description = "更新员工请求")
    public static class EmployeeUpdateRequest {
        @Schema(description = "员工ID")
        private Long id;

        @Schema(description = "姓名")
        private String realName;

        @Schema(description = "邮箱")
        private String email;

        @Schema(description = "手机号")
        private String phone;

        @Schema(description = "角色")
        private Integer role;

        @Schema(description = "部门")
        private String department;

        @Schema(description = "职位")
        private String position;

        @Schema(description = "备注")
        private String remark;
    }

    @Data
    @Schema(description = "员工密码重置请求")
    public static class EmployeePasswordResetRequest {
        @Schema(description = "员工ID")
        private Long employeeId;

        @NotBlank(message = "新密码不能为空")
        @Size(min = 6, max = 20, message = "密码长度必须在6-20个字符之间")
        @Schema(description = "新密码")
        private String newPassword;
    }

    @Data
    @Schema(description = "员工状态更新请求")
    public static class EmployeeStatusUpdateRequest {
        @Schema(description = "员工ID")
        private Long employeeId;

        @NotNull(message = "状态不能为空")
        @Schema(description = "状态（0禁用/1启用）")
        private Integer status;
    }
}
