"""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 CUSTOMERS_CREATE, CUSTOMERS_VIEW
from app.schemas.customers import CustomerProfileCreate, CustomerProfileRead
from app.services.customers import CustomerProfileService


customerProfile_router = APIRouter()

@customerProfile_router.post("", response_model=CustomerProfileRead, status_code=status.HTTP_201_CREATED)
async def create_customerProfile(body: CustomerProfileCreate, tenant_id: UUID = Depends(require_tenant), db: AsyncSession = Depends(get_db), user: CurrentUser = Depends(require_permissions(CUSTOMERS_CREATE))):
    return await CustomerProfileService(db).create(tenant_id, body, actor=user)

@customerProfile_router.get("", response_model=list[CustomerProfileRead])
async def list_customerProfile(tenant_id: UUID = Depends(require_tenant), pagination: PaginationParams = Depends(get_pagination), db: AsyncSession = Depends(get_db), _user: CurrentUser = Depends(require_permissions(CUSTOMERS_VIEW))):
    return await CustomerProfileService(db).list(tenant_id, offset=pagination.offset, limit=pagination.page_size)

@customerProfile_router.get("/{entity_id}", response_model=CustomerProfileRead)
async def get_customerProfile(entity_id: UUID, tenant_id: UUID = Depends(require_tenant), db: AsyncSession = Depends(get_db), _user: CurrentUser = Depends(require_permissions(CUSTOMERS_VIEW))):
    return await CustomerProfileService(db).get(tenant_id, entity_id)
