package cn.iocoder.yudao.module.system.controller.admin.user.vo.user;

import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.validation.Mobile;
import cn.iocoder.yudao.module.system.dal.dataobject.user.*;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserEducationDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserFamilySituationDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserQualificationDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserRewardsPunishmentsDO;
import cn.iocoder.yudao.module.system.framework.operatelog.core.DeptParseFunction;
import cn.iocoder.yudao.module.system.framework.operatelog.core.PostParseFunction;
import cn.iocoder.yudao.module.system.framework.operatelog.core.SexParseFunction;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mzt.logapi.starter.annotation.DiffLogField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Set;

@Schema(description = "管理后台 - 用户创建/修改 Request VO")
@Data
public class UserSaveReqVO {

    @Schema(description = "用户编号", example = "1024")
    private Long id;

    @Schema(description = "登录账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
    @NotBlank(message = "登录账号不能为空")
    @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "登录账号由 数字、字母 组成")
    @Size(min = 4, max = 30, message = "登录账号长度为 4-30 个字符")
    @DiffLogField(name = "登录账号")
    private String username;

    @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
    @Size(max = 30, message = "用户昵称长度不能超过30个字符")
    @DiffLogField(name = "用户昵称")
    private String nickname;

    @Schema(description = "备注", example = "我是一个用户")
    @DiffLogField(name = "备注")
    private String remark;

    @Schema(description = "部门编号", example = "我是一个用户")
    @DiffLogField(name = "部门", function = DeptParseFunction.NAME)
    private Long deptId;

    @Schema(description = "岗位编号数组", example = "1")
    @DiffLogField(name = "岗位", function = PostParseFunction.NAME)
    private Set<Long> postIds;

    @Schema(description = "用户邮箱", example = "yudao@iocoder.cn")
    @Email(message = "邮箱格式不正确")
    @Size(max = 50, message = "邮箱长度不能超过 50 个字符")
    @DiffLogField(name = "用户邮箱")
    private String email;

    @Schema(description = "手机号码", example = "15601691300")
    @Mobile
    @DiffLogField(name = "手机号码")
    private String mobile;

    @Schema(description = "用户性别，参见 SexEnum 枚举类", example = "1")
    @DiffLogField(name = "用户性别", function = SexParseFunction.NAME)
    private Integer sex;

    @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
    @DiffLogField(name = "用户头像")
    private String avatar;

    @Schema(description = "用户编号")
    private String userNumber;

    @Schema(description = "用户类型")
    private Integer userType;

    @Schema(description = "证件类型", example = "1")
    private String idType;

    @Schema(description = "证件号码")
    private String idNumber;

    @Schema(description = "出生日期")
    private LocalDate birthday;

    @Schema(description = "民族")
    private String nation;

    @Schema(description = "籍贯")
    private String nativePlace;

    @Schema(description = "居住地址")
    private String residentialAddress;

    @Schema(description = "是否党员")
    private String isPartyMember;

    @Schema(description = "婚姻状况", example = "1")
    private String maritalStatus;

    @Schema(description = "最高学历")
    private String highestDegree;

    @Schema(description = "毕业院校")
    private String graduateSchool;

    @Schema(description = "专业")
    private String major;

    @Schema(description = "毕业年份")
    private String graduationYear;

    @Schema(description = "是否有护理等级证书")
    private String isHaveNursingLevelCertificate;

    @Schema(description = "是否缴纳社保")
    private String isPaySocialSecurity;

    @Schema(description = "职务")
    private String job;

    @Schema(description = "入职日期")
    private LocalDate joinedDate;

    @Schema(description = "试用期（月）")
    private String trialPeriod;

    @Schema(description = "试用期工资(元)")
    private BigDecimal probationarySalary;

    @Schema(description = "转正工资(元)")
    private BigDecimal regularSalary;

    @Schema(description = "身份证人像照")
    private String idCardPortraitPhoto;

    @Schema(description = "身份证国徽照")
    private String nationalEmblemPhoto;

    @Schema(description = "工作状态")
    private Integer workStatus;

    @Schema(description = "银行卡正面照")
    private String bankCardFrontPhoto;

    @Schema(description = "银行卡反面照")
    private String bankCardBackPhoto;

    @Schema(description = "银行卡号")
    private String bankCardNumber;

    @Schema(description = "银行名称", example = "张三")
    private String bankCardName;

    @Schema(description = "入职告知书")
    private String employmentNoticeFile;

    @Schema(description = "技能证书")
    private String skillsCertificateFile;

    @Schema(description = "体检报告")
    private String medicalReport;

    @Schema(description = "护理员等级")
    private String nursingStaffLevel;

    /**
     * 企微id
     */
    private String corpUserId;

    private Integer orgType;

    @Schema(description = "用户教育经历")
    private List<AdminUserEducationDO> userEducations;

    @Schema(description = "用户家庭情况")
    private List<AdminUserFamilySituationDO> userFamilySituations;

    @Schema(description = "用户资质列表")
    private List<AdminUserQualificationDO> userQualifications;

    @Schema(description = "用户奖惩列表")
    private List<AdminUserRewardsPunishmentsDO> userRewardsPunishments;

    @Schema(description = "用户补贴")
    private List<AdminUserSubsidyDO> userSubsidy;

    @Schema(description = "用户培训经历")
    private List<AdminUserTrainingExperienceDO> userTrainingExperiences;

    @Schema(description = "用户工作经历")
    private List<AdminUserWorkExperienceDO> userWorkExperiences;


    private String isEnableEnterpriseLogin;



    // ========== 仅【创建】时，需要传递的字段 ==========

    @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
    @Length(min = 4, max = 16, message = "密码长度为 4-16 位")
    private String password;

    @AssertTrue(message = "密码不能为空")
    @JsonIgnore
    public boolean isPasswordValid() {
        return id != null // 修改时，不需要传递
                || (ObjectUtil.isAllNotEmpty(password)); // 新增时，必须都传递 password
    }

}
