"""Hospitality tenant bundles APIs — Phase 12.0."""
from __future__ import annotations

from uuid import UUID

from fastapi import APIRouter, Depends, status
from sqlalchemy.ext.asyncio import AsyncSession

from app.api.deps import get_db, get_pagination, require_tenant
from app.core.security import get_current_user
from app.schemas.foundation import TenantBundleActivate, TenantBundleRead
from app.services.foundation import TenantBundleService
from shared.pagination import PaginationParams
from shared.security import CurrentUser

router = APIRouter()


@router.post("/activate", response_model=TenantBundleRead, status_code=status.HTTP_201_CREATED)
async def activate_bundle(
    body: TenantBundleActivate,
    tenant_id: UUID = Depends(require_tenant),
    db: AsyncSession = Depends(get_db),
    user: CurrentUser = Depends(get_current_user),
):
    return await TenantBundleService(db).activate(tenant_id, body, actor=user)


@router.post("/{bundle_id}/deactivate", response_model=TenantBundleRead)
async def deactivate_bundle(
    bundle_id: UUID,
    tenant_id: UUID = Depends(require_tenant),
    db: AsyncSession = Depends(get_db),
    user: CurrentUser = Depends(get_current_user),
):
    return await TenantBundleService(db).deactivate(tenant_id, bundle_id, actor=user)


@router.get("", response_model=list[TenantBundleRead])
async def list_items(
    tenant_id: UUID = Depends(require_tenant),
    pagination: PaginationParams = Depends(get_pagination),
    db: AsyncSession = Depends(get_db),
    _user: CurrentUser = Depends(get_current_user),
):
    return await TenantBundleService(db).list(tenant_id, offset=pagination.offset, limit=pagination.page_size)


@router.get("/{bundle_id}", response_model=TenantBundleRead)
async def get_item(
    bundle_id: UUID,
    tenant_id: UUID = Depends(require_tenant),
    db: AsyncSession = Depends(get_db),
    _user: CurrentUser = Depends(get_current_user),
):
    return await TenantBundleService(db).get(tenant_id, bundle_id)
