from pydantic import BaseModel, ConfigDict, Field


class EvaluationPointGroupCreateDTO(BaseModel):
    """创建评查点分组请求。"""

    name: str = Field(..., description="分组名称")
    code: str = Field(..., description="分组编码")
    pid: int | None = Field(None, description="父分组ID，空或 0 表示一级业务分组")
    description: str | None = Field(None, description="分组描述")
    document_type_id: int | None = Field(None, description="关联文档类型ID；一级通常留空仅用于兼容旧数据，二级需绑定具体文档类型")
    entry_module_id: int | None = Field(None, description="关联入口模块ID；一级业务分组可绑定，允许后补")
    sort_order: int = Field(0, description="排序")
    is_enabled: bool = Field(True, description="是否启用")


class EvaluationPointGroupUpdateDTO(BaseModel):
    """更新评查点分组请求。"""

    name: str | None = Field(None, description="分组名称")
    code: str | None = Field(None, description="分组编码")
    pid: int | None = Field(None, description="父分组ID，空或 0 表示一级业务分组")
    description: str | None = Field(None, description="分组描述")
    document_type_id: int | None = Field(None, description="关联文档类型ID；一级通常留空仅用于兼容旧数据，二级需绑定具体文档类型")
    entry_module_id: int | None = Field(None, description="关联入口模块ID；一级业务分组可绑定，允许后补")
    sort_order: int | None = Field(None, description="排序")
    is_enabled: bool | None = Field(None, description="是否启用")


class EvaluationPointGroupRebindDTO(BaseModel):
    """文档类型分组换绑请求。"""

    new_parent_id: int = Field(..., ge=1, description="新的文档类型分组ID")


class EvaluationPointGroupBatchStatusDTO(BaseModel):
    """批量更新状态请求。"""

    ids: list[int] = Field(default_factory=list, description="分组ID列表")
    is_enabled: bool = Field(..., description="目标启用状态")


class EvaluationPointGroupBatchDeleteDTO(BaseModel):
    """批量删除分组请求。"""

    ids: list[int] = Field(default_factory=list, description="分组ID列表")


class EvaluationPointGroupBindingCreateDTO(BaseModel):
    """规则组绑定创建请求。"""

    rule_set_id: int = Field(..., ge=1, description="规则集ID")
    priority: int = Field(0, description="优先级")
    is_active: bool = Field(True, description="是否启用")
    note: str | None = Field(None, description="备注")


class EvaluationPointGroupBindingUpdateDTO(BaseModel):
    """规则组绑定更新请求。"""

    priority: int | None = Field(None, description="优先级")
    is_active: bool | None = Field(None, description="是否启用")
    note: str | None = Field(None, description="备注")


class EvaluationPointGroupRuleDraftCreateDTO(BaseModel):
    """二级分组下新建规则 YAML 草稿请求。"""

    model_config = ConfigDict(populate_by_name=True)

    yaml_text: str = Field(..., min_length=1, alias="yamlText", description="完整规则 YAML 正文")
    change_note: str | None = Field(None, alias="changeNote", description="版本变更说明")
    editor_user_id: int | None = Field(None, alias="editorUserId", description="编辑者用户ID")
