"""道体铸魂与分灵 API(/characters/{id}/soul)。""" from fastapi import APIRouter, Depends from pydantic import BaseModel, Field from app.api.v1.deps import get_current_user from app.domains.jingsheng import soul from app.schemas.auth import CurrentUser soul_router = APIRouter(prefix="/characters/{character_id}/soul", tags=["jingsheng"]) class ForgingRequest(BaseModel): anchor_changes: dict = Field(description="道体锚点变更(键:identity_baseline_json)") reason: str = Field(min_length=1, max_length=2000) class SplitRequest(BaseModel): reason: str = Field(min_length=1, max_length=2000) initial_anchor: dict = Field(default_factory=dict) @soul_router.get("/forgings") async def list_forgings( character_id: str, user: CurrentUser = Depends(get_current_user) ) -> list[dict]: return await soul.list_forgings(character_id, user.owner_scope) @soul_router.post("/forgings", status_code=201) async def propose_forging( character_id: str, payload: ForgingRequest, user: CurrentUser = Depends(get_current_user) ) -> dict: return await soul.propose_forging( character_id=character_id, owner_scope=user.owner_scope, anchor_changes=payload.anchor_changes, reason=payload.reason, ) @soul_router.post("/forgings/{forging_id}/confirm") async def confirm_forging( character_id: str, forging_id: str, user: CurrentUser = Depends(get_current_user) ) -> dict: return await soul.confirm_forging(forging_id, user.owner_scope) @soul_router.post("/forgings/{forging_id}/reject") async def reject_forging( character_id: str, forging_id: str, user: CurrentUser = Depends(get_current_user) ) -> dict: return await soul.reject_forging(forging_id, user.owner_scope) @soul_router.post("/split", status_code=201) async def split_soul( character_id: str, payload: SplitRequest, user: CurrentUser = Depends(get_current_user) ) -> dict: return await soul.split_soul( character_id=character_id, owner_scope=user.owner_scope, reason=payload.reason, initial_anchor=payload.initial_anchor, ) @soul_router.get("/lineage") async def get_lineage( character_id: str, user: CurrentUser = Depends(get_current_user) ) -> list[dict]: return await soul.get_lineage(character_id, user.owner_scope)