"""API routes."""
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.api.permissions import require_permissions
from shared.pagination import PaginationParams
from shared.security import CurrentUser

from app.permissions.definitions import SERVICES_CREATE, SERVICES_VIEW
from app.permissions.definitions import SERVICE_CATEGORIES_CREATE, SERVICE_CATEGORIES_VIEW
from app.schemas.catalog import BeautyServiceCreate, BeautyServiceRead
from app.schemas.catalog import ServiceCategoryCreate, ServiceCategoryRead
from app.services.catalog import BeautyServiceService
from app.services.catalog import ServiceCategoryService


serviceCategory_router = APIRouter()

@serviceCategory_router.post("", response_model=ServiceCategoryRead, status_code=status.HTTP_201_CREATED)
async def create_serviceCategory(body: ServiceCategoryCreate, tenant_id: UUID = Depends(require_tenant), db: AsyncSession = Depends(get_db), user: CurrentUser = Depends(require_permissions(SERVICE_CATEGORIES_CREATE))):
    return await ServiceCategoryService(db).create(tenant_id, body, actor=user)

@serviceCategory_router.get("", response_model=list[ServiceCategoryRead])
async def list_serviceCategory(tenant_id: UUID = Depends(require_tenant), pagination: PaginationParams = Depends(get_pagination), db: AsyncSession = Depends(get_db), _user: CurrentUser = Depends(require_permissions(SERVICE_CATEGORIES_VIEW))):
    return await ServiceCategoryService(db).list(tenant_id, offset=pagination.offset, limit=pagination.page_size)

@serviceCategory_router.get("/{entity_id}", response_model=ServiceCategoryRead)
async def get_serviceCategory(entity_id: UUID, tenant_id: UUID = Depends(require_tenant), db: AsyncSession = Depends(get_db), _user: CurrentUser = Depends(require_permissions(SERVICE_CATEGORIES_VIEW))):
    return await ServiceCategoryService(db).get(tenant_id, entity_id)


beautyService_router = APIRouter()

@beautyService_router.post("", response_model=BeautyServiceRead, status_code=status.HTTP_201_CREATED)
async def create_beautyService(body: BeautyServiceCreate, tenant_id: UUID = Depends(require_tenant), db: AsyncSession = Depends(get_db), user: CurrentUser = Depends(require_permissions(SERVICES_CREATE))):
    return await BeautyServiceService(db).create(tenant_id, body, actor=user)

@beautyService_router.get("", response_model=list[BeautyServiceRead])
async def list_beautyService(tenant_id: UUID = Depends(require_tenant), pagination: PaginationParams = Depends(get_pagination), db: AsyncSession = Depends(get_db), _user: CurrentUser = Depends(require_permissions(SERVICES_VIEW))):
    return await BeautyServiceService(db).list(tenant_id, offset=pagination.offset, limit=pagination.page_size)

@beautyService_router.get("/{entity_id}", response_model=BeautyServiceRead)
async def get_beautyService(entity_id: UUID, tenant_id: UUID = Depends(require_tenant), db: AsyncSession = Depends(get_db), _user: CurrentUser = Depends(require_permissions(SERVICES_VIEW))):
    return await BeautyServiceService(db).get(tenant_id, entity_id)
