from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="直播接管控制接口")

# 由 main.py 在启动前注入：app.state.shared_config = <Manager().dict(...)>
app.shared_config = None


class ControlMode(BaseModel):
    control_mode: int  # 0=手动接管, 1=AI接管


@app.post("/control-mode", summary="更新直播间接管模式")
def update_control_mode(mode: ControlMode):
    if app.shared_config is None:
        return {"error": "服务未初始化"}
    app.shared_config["control_mode"] = mode.control_mode
    return {
        "message": "模式更新成功",
        "current_status": {
            "control_mode": app.shared_config["control_mode"],  # 0=手动, 1=AI
        },
    }
