"""items 域依赖：MySQL(SQLAlchemy async) 仓储。"""

from typing import Annotated, Protocol

from fastapi import Depends
from sqlalchemy.ext.asyncio import AsyncSession

from src.database import get_db
from src.items.mysql import MySQLItemRepo
from src.items.schemas import ItemCreate, ItemOut, ItemUpdate


class ItemRepo(Protocol):
    """仓储协议：业务层只依赖它，不关心底层实现。"""

    async def create(self, data: ItemCreate) -> ItemOut: ...
    async def get(self, item_id: str) -> ItemOut | None: ...
    async def list(self, skip: int = 0, limit: int = 20) -> tuple[int, list[ItemOut]]: ...
    async def update(self, item_id: str, data: ItemUpdate) -> ItemOut | None: ...
    async def delete(self, item_id: str) -> bool: ...


async def get_item_repo(session: Annotated[AsyncSession, Depends(get_db)]) -> ItemRepo:
    return MySQLItemRepo(session)


ItemRepoDep = Annotated[ItemRepo, Depends(get_item_repo)]
