package com.fs.course.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fs.common.annotation.Excel;
import com.fs.common.core.domain.BaseEntity;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 完课模板对象 fs_course_finish_temp
 *
 * @author fs
 * @date 2024-12-19
 */
@Data
public class FsCourseFinishTemp extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** $column.columnComment */
    private Long id;

    /** 模板名称 */
    @Excel(name = "模板名称")
    private String name;

    /** 状态 1正常 0停用 */
    @Excel(name = "状态 1正常 0停用")
    private Long status;

    /** 看课规则（完课后私聊发送） */
    @Excel(name = "看课规则")
    private String setting;

    /** 群聊恭喜规则（完课后群聊发送） */
    @Excel(name = "群聊恭喜规则")
    private String chatSetting;

    /** 公司id */
    @Excel(name = "公司id")
    private Long companyId;

    /** 课程id */
    @Excel(name = "课程id")
    private Long courseId;

    /** 小节视频id */
    @Excel(name = "小节视频id")
    private Long videoId;

    /** 归属销售id(对多) */
    @Excel(name = "归属销售id(对多)")
    private String companyUserIds;
    private Long parentId;

    /** 删除标志 */
    @Excel(name = "删除标志")
    private Long isDel;

    @Excel(name = "全选销售标志")
    private Integer isAllCompanyUser;

    /**
     * 用于批量更新状态
     */
    @TableField(exist = false)
    private List<Long> ids;

    @TableField(exist = false)
    private List<String> userIds = new ArrayList<>();

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

        // 直接在原始列表上修改
        for (int i = 0; i < userIds.size(); i++) {
            String id = userIds.get(i);
            if (id != null) {
                if (id.startsWith("dept_")) {
                    userIds.set(i, id.substring(5));
                } else if (id.startsWith("company_")) {
                    userIds.set(i, id.substring(8));
                } else if (id.startsWith("user_")) {
                    userIds.set(i, id.substring(5));
                }
            }
        }
        return userIds;
    }
}
