from typing import Annotated

from fastapi import APIRouter, Depends
from psycopg import Connection
from pydantic import BaseModel, Field
from src.__types.index import Tenant
from src.domain.entities.attention import Attention
from src.routers.management.authorizer import get_tenant
from src.routers.management.connection import get_connection
from src.tracer import tracer
from src.usecases.attention_usecase import AttentionUseCase

router = APIRouter(
    prefix="/attentions",
    tags=["アテンション"],
)


class GetResponse(BaseModel):
    """アテンションを取得するレスポンスモデル"""

    attentions: list[Attention] = Field(..., description="アテンションのリスト")


@router.get(
    "",
    summary="取得",
    description="現在のクォータ使用実績から計算したアテンションを取得します。",
)
@tracer.capture_method
def get(
    tenant: Annotated[Tenant, Depends(get_tenant)],
    connection: Annotated[Connection, Depends(get_connection)],
) -> GetResponse:
    usecase = AttentionUseCase.create(tenant=tenant, connection=connection)
    return GetResponse(
        attentions=usecase.get(),
    )
