package com.njcn.rdms.module.project.controller.admin.project.vo.project;

import com.njcn.rdms.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Schema(description = "管理后台 - 项目按产品分组分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class ProjectGroupPageReqVO extends PageParam {

    @Schema(description = "关键词，匹配项目编码或项目名称", example = "CNPJ2026001")
    private String keyword;

    @Schema(description = "项目类型字典值", example = "main")
    @Size(max = 32, message = "项目类型长度不能超过32个字符")
    private String projectType;

    @Schema(description = "所属产品编号", example = "1001")
    private Long productId;

    @Schema(description = "项目状态编码；缺省 = 「全部」口径（状态机启用状态，不含已取消/已归档）", example = "active")
    @Size(max = 32, message = "项目状态编码长度不能超过32个字符")
    private String statusCode;

    @Schema(description = "仅返回游离组（未挂产品的项目），不可与 productId 同时使用", example = "true")
    private Boolean orphanOnly;

    @Schema(description = "每组返回项目条数上限，默认 5", example = "5")
    @Min(value = 1, message = "每组条数最小值为 1")
    @Max(value = 50, message = "每组条数最大值为 50")
    private Integer topN = 5;

    @AssertTrue(message = "游离组筛选与产品筛选不能同时使用")
    @Schema(hidden = true)
    public boolean isOrphanFilterValid() {
        return !Boolean.TRUE.equals(orphanOnly) || productId == null;
    }

}
