"""管理员：默认 OEM（id=1）软件品牌配置。"""

from fastapi import APIRouter

from app.dependencies import OemUser, DbSession
from app.schemas.admin_oem_branding import OemBrandingOut, OemBrandingUpdate
from app.schemas.common import ApiResponse
from app.services import oem_oem_branding as branding_service

router = APIRouter(prefix="/oem/oem-branding", tags=["管理-OEM品牌"])


@router.get("", response_model=ApiResponse[OemBrandingOut])
async def get_oem_branding(
    admin: OemUser,
    db: DbSession,
) -> ApiResponse[OemBrandingOut]:
    try:
        oem = await branding_service.get_default_oem_branding(db, user_id=admin.id)
    except branding_service.AdminOemBrandingError as exc:
        return ApiResponse(ok=False, message=exc.message)

    return ApiResponse(
        ok=True,
        message="",
        data=OemBrandingOut.model_validate(oem),
    )


@router.patch("", response_model=ApiResponse[OemBrandingOut])
async def update_oem_branding(
    body: OemBrandingUpdate,
    admin: OemUser,
    db: DbSession,
) -> ApiResponse[OemBrandingOut]:
    try:
        oem = await branding_service.update_default_oem_branding(db, body, user_id=admin.id)
    except branding_service.AdminOemBrandingError as exc:
        return ApiResponse(ok=False, message=exc.message)

    return ApiResponse(
        ok=True,
        message="软件配置已保存",
        data=OemBrandingOut.model_validate(oem),
    )
