package jnpf.model.cultivate.dto.offline;

import cn.hutool.core.collection.CollUtil;
import jnpf.model.cultivate.po.offline.FtbCultivateOfflineCourse;
import jnpf.model.cultivate.po.offline.FtbCultivateOfflineTrain;
import jnpf.model.cultivate.po.offline.FtbCultivateOfflineUser;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;


/**
 * 线下培训入参
 *
 * @author fantaibao
 * @date 2023/12/17
 */
@Data
public class FtbCultivateOfflineTrainDTO {

    /**
     * 培训名称
     */
    @NotBlank(message = "培训名称不能为空")
    @Length(max = 50, message = "培训名称长度不能超过50字")
    private String name;

    /**
     * 培训地点
     */
    @NotBlank(message = "培训地点不能为空")
    @Length(max = 100, message = "培训地点长度不能超过100字")
    private String offlinePlace;

    /**
     * 申请人ID
     */
    @NotBlank(message = "申请人ID不能为空")
    private String userId;

    /**
     * 负责人ID
     */
    @NotBlank(message = "负责人ID不能为空")
    private String headUserId;

    /**
     * 附件信息
     */
    @Size(max = 3, message = "附件信息上限3个")
    @Valid
    private List<FtbCultivateOfflineFileDTO> files;

    /**
     * 培训开始时间
     */
    @NotNull(message = "培训开始时间不能为空")
    private Date trainStartTime;

    /**
     * 培训结束时间
     */
    @NotNull(message = "培训结束时间不能为空")
    private Date trainEndTime;

    /**
     * 培训内容
     */
    @NotBlank(message = "培训内容不能为空")
    @Length(max = 1000, message = "培训内容长度不能超过1000字")
    private String trainContent;

    /**
     * 参与培训人员id集合
     */
    @NotNull(message = "参与培训人员id集合不能为空")
    @Size(min = 1, message = "请勾选参与培训人员")
    private List<String> userIds;

    /**
     * 签到方式，0一键签到，1拍照签到
     */
    @NotNull(message = "签到方式不能为空")
    private Integer signWay;

    /**
     * 课程id集合
     */
    private List<String> courseIds;


    /**
     * 实体转换
     *
     * @param ftbCultivateOfflineTrainDTO
     * @return {@link FtbCultivateOfflineTrain}
     */
    public FtbCultivateOfflineTrain convertFtbCultivateOfflineTrain(FtbCultivateOfflineTrainDTO ftbCultivateOfflineTrainDTO) {
        if (ftbCultivateOfflineTrainDTO == null) {
            return null;
        }
        FtbCultivateOfflineTrain ftbCultivateOfflineTrain = new FtbCultivateOfflineTrain();
        ftbCultivateOfflineTrain.setState(0);
        ftbCultivateOfflineTrain.setName(ftbCultivateOfflineTrainDTO.getName());
        ftbCultivateOfflineTrain.setOfflinePlace(ftbCultivateOfflineTrainDTO.getOfflinePlace());
        ftbCultivateOfflineTrain.setUserId(ftbCultivateOfflineTrainDTO.getUserId());
        ftbCultivateOfflineTrain.setHeadUserId(ftbCultivateOfflineTrainDTO.getHeadUserId());
        ftbCultivateOfflineTrain.setTrainStartTime(ftbCultivateOfflineTrainDTO.getTrainStartTime());
        ftbCultivateOfflineTrain.setTrainEndTime(ftbCultivateOfflineTrainDTO.getTrainEndTime());
        ftbCultivateOfflineTrain.setTrainContent(ftbCultivateOfflineTrainDTO.getTrainContent());
        ftbCultivateOfflineTrain.setSignWay(ftbCultivateOfflineTrainDTO.getSignWay());
        if (CollUtil.isNotEmpty(ftbCultivateOfflineTrainDTO.getUserIds())) {
            ftbCultivateOfflineTrain.setParticipants(String.join(",", ftbCultivateOfflineTrainDTO.getUserIds()));
        }
        return ftbCultivateOfflineTrain;
    }

    /**
     * 实体转换
     *
     * @param userId 用户 ID
     * @return {@link FtbCultivateOfflineUser}
     */
    public static FtbCultivateOfflineUser convertFtbCultivateOfflineUser(String userId) {
        FtbCultivateOfflineUser ftbCultivateOfflineUser = new FtbCultivateOfflineUser();
        ftbCultivateOfflineUser.setUserId(userId);
        return ftbCultivateOfflineUser;
    }

    /**
     * 实体转换
     *
     * @param courseId 课程id
     * @return {@link FtbCultivateOfflineCourse}
     */
    public static FtbCultivateOfflineCourse convertFtbCultivateOfflineCourse(String courseId) {
        FtbCultivateOfflineCourse ftbCultivateOfflineCourse = new FtbCultivateOfflineCourse();
        ftbCultivateOfflineCourse.setCourseId(courseId);
        return ftbCultivateOfflineCourse;
    }

}