package com.fs.course.param;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class FsCourseWatchLogListParam implements Serializable {

    private Long logId;

    private Long userId;

    private Long qwUserId;

    private Long companyId;

    private Long companyUserId;

    private String companyUserName;
    private String nickName;
    private String externalUserName;
    private Long qwExternalContactId;

    private Long courseId;

    private Long videoId;

    private Integer logType;

    private String sopDate;

    private Integer sendType;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String eTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String sTime;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private String upSTime;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String upETime;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private String scheduleStartTime;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String scheduleEndTime;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private String qecSTime;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String qecETime;


    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String periodSTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String periodETime;

    private List<String> sopIds;


    private Long taskId;//任务ID
    //private Long project;//任务ID

    private List<Long> periodIds;//训练营期ID

    private Long periodId;//训练营期ID

    private String customPageStr;

    private Long lastId;

    /**
     * 销售部门
     */
    private List<Long> cuDeptIdList;

    /**
     * 部门类型 00 管理员 01 员工
     */
    private String userType;

    /**
     * 是否是会员
     */
    private Integer isVip;

    /**
     * 会员状态 正常、删除、接替、拉黑等等
     * */
    private Integer externalStatus;

    /**
     * 所属项目
     */
    private Integer project;

    /**
     * sop主键id
     */
    private String sopId;

    /**
     * 企微名称
     */
    private String qwUserName;
    private Long deptId;
    private List<Long> deptIds;
    private String ids;

    private Long id;

    private Date createTime;

    private String appid;

    private Integer pageNum;
    private Integer pageSize;
    private List<String> userIds;
    private Integer watchType;

    /** 企微主体 corpId */
    private String corpId;

    /**
     * 客户标签 ID 列表（解析后供 Mapper 使用）
     */
    private List<String> tagIds;

    /**
     * 客户标签 ID（逗号分隔，GET 传参用，避免数组序列化问题）
     */
    private String tagIdList;

    /**
     * 标签匹配规则：1=含全部标签（同时包含所选全部，与顺序无关），2=含任意标签，默认任意
     */
    private Integer tagFilterType;

    public List<String> getUserIds() {
        if (userIds == null || userIds.isEmpty()) {
            return userIds;
        }

        return userIds.stream()
                .map(id -> {
                    if (id == null) {
                        return null;
                    }
                    // 去除前缀
                    if (id.startsWith("dept_")) {
                        return "0";
                    } else if (id.startsWith("company_")) {
                        return "0";
                    } else if (id.startsWith("user_")) {
                        return id.substring(5);
                    }
                    return "0";
                })
                .collect(Collectors.toList());
    }
}
