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

import com.njcn.rdms.framework.common.pojo.PageParam;
import com.njcn.rdms.framework.dict.validation.InDict;
import com.njcn.rdms.module.system.enums.DictTypeConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.List;

import static com.njcn.rdms.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;

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

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

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

    @Schema(description = "项目方向字典值", example = "direction_value")
    @InDict(type = DictTypeConstants.OBJECT_DIRECTION)
    private String directionCode;

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

    @Schema(description = "项目负责人用户编号", example = "1024")
    private Long managerUserId;

    @Schema(description = "项目状态编码", example = "active")
    @Size(max = 32, message = "项目状态编码长度不能超过32个字符")
    private String statusCode;

    @Schema(description = "更新时间", example = "[2026-04-01 00:00:00, 2026-04-30 23:59:59]")
    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
    private LocalDateTime[] updateTime;

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

    @Schema(description = "项目状态编码集合，存在时优先于 statusCode 生效", example = "[\"pending\", \"active\"]")
    private List<String> statusCodes;

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

}
