package com.ruoyi.ccdi.project.domain.dto;

import jakarta.validation.constraints.Pattern;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Data;

/**
 * 风险模型命中人员查询DTO
 */
@Data
public class CcdiProjectRiskModelPeopleQueryDTO {

    /** 项目ID */
    private Long projectId;

    /** 模型编码列表 */
    private List<String> modelCodes;

    /** 匹配方式 */
    @Pattern(regexp = "ANY|ALL", message = "匹配方式仅支持ANY或ALL")
    private String matchMode;

    /** 关键字 */
    private String keyword;

    /** 部门ID */
    private Long deptId;

    /** 页码 */
    private Integer pageNum;

    /** 每页数量 */
    private Integer pageSize;

    public String getModelCodesCsv() {
        if (modelCodes == null || modelCodes.isEmpty()) {
            return null;
        }
        return modelCodes.stream()
            .filter(item -> item != null && !item.isBlank())
            .map(String::trim)
            .distinct()
            .collect(Collectors.joining(","));
    }

    public Integer getModelCodesCount() {
        String modelCodesCsv = getModelCodesCsv();
        if (modelCodesCsv == null || modelCodesCsv.isBlank()) {
            return 0;
        }
        return modelCodesCsv.split(",").length;
    }
}
