from fastapi import APIRouter, Depends
from auth.models import TokenPayload
from auth.dependencies import require_permission, require_roles
from auth.models import Role
from settings.models import MelodySettings, MelodySettingsUpdate
from settings.public_features_models import PublicFeaturesSettings, PublicFeaturesSettingsUpdate
from settings import service
from settings import public_features_service

router = APIRouter(prefix="/api/settings", tags=["settings"])


@router.get("/melody", response_model=MelodySettings)
async def get_melody_settings(
    _user: TokenPayload = Depends(require_permission("melodies", "view")),
):
    return service.get_melody_settings()


@router.put("/melody", response_model=MelodySettings)
async def update_melody_settings(
    body: MelodySettingsUpdate,
    _user: TokenPayload = Depends(require_permission("melodies", "edit")),
):
    return service.update_melody_settings(body)


# ── Public Features Settings (sysadmin / admin only) ─────────────────────────

@router.get("/public-features", response_model=PublicFeaturesSettings)
async def get_public_features(
    _user: TokenPayload = Depends(require_roles(Role.sysadmin, Role.admin)),
):
    return public_features_service.get_public_features()


@router.put("/public-features", response_model=PublicFeaturesSettings)
async def update_public_features(
    body: PublicFeaturesSettingsUpdate,
    _user: TokenPayload = Depends(require_roles(Role.sysadmin, Role.admin)),
):
    return public_features_service.update_public_features(body)
