package com.fs.course.param;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fs.common.utils.DateUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Data
public class FsCourseWatchLogStatisticsListParam {

    private Long companyId;
    private Long companyUserId;
    private Long userId;

    private String nickName;

    private Long courseId;

    private Long videoId;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date eTime;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date sTime;

    private String startDate;
    private String endDate;

    public String getStartDate() {
        return DateUtils.getStartOfDayString(sTime);
    }

    public String getEndDate() {
        return DateUtils.getEndOfDayString(eTime);
    }

    private String startTime;

    private String endTime;

    private String qwSopId;

    private Long project;

    private Long pageNum;
    private Long pageSize;

    private Integer sendType; //归属发送方式：1 个微  2 企微

    /**
     * 公司ids
     */
    private  List<Long> companyIds;

    /**
     * 标识('course','company')
     */
    private  String dimension ;
    /**
     * 今正要求把公司筛选条件优化到细分至部门，销售（前端判断，只有今正传）
     */
    private List<String> userIds;
    public List<String> getUserIds() {
        if (userIds == null || userIds.isEmpty()) {
            return userIds;
        }
        ArrayList<String> longs = new ArrayList<>();
        userIds.forEach(userId -> {
            if (userId.contains("user_")){
                StringJoiner joiner = new StringJoiner("");
                Matcher matcher = Pattern.compile("\\d+").matcher(userId);
                while (matcher.find()) {
                    joiner.add(matcher.group());
                }
                longs.add(joiner.toString());
            }
        });
        return longs;
    }
}
