"""Model listing and leaderboard."""

from __future__ import annotations

from typing import Any, Dict, Optional

from .._resource import AsyncResource, Resource


class Models(Resource):
    """Sync model operations."""

    def list(self) -> Dict[str, Any]:
        """List available models for the authenticated tenant."""
        return self._get("/v1/models")

    def leaderboard(
        self,
        *,
        sort: Optional[str] = None,
        provider: Optional[str] = None,
        limit: Optional[int] = None,
        offset: Optional[int] = None,
    ) -> Dict[str, Any]:
        """Get model performance leaderboard ranked by Thompson sampling reward scores."""
        query: Dict[str, str] = {}
        if sort is not None:
            query["sort"] = sort
        if provider is not None:
            query["provider"] = provider
        if limit is not None:
            query["limit"] = str(limit)
        if offset is not None:
            query["offset"] = str(offset)
        return self._get("/v1/models/leaderboard", query or None)


class AsyncModels(AsyncResource):
    """Async model operations."""

    async def list(self) -> Dict[str, Any]:
        return await self._get("/v1/models")

    async def leaderboard(
        self,
        *,
        sort: Optional[str] = None,
        provider: Optional[str] = None,
        limit: Optional[int] = None,
        offset: Optional[int] = None,
    ) -> Dict[str, Any]:
        query: Dict[str, str] = {}
        if sort is not None:
            query["sort"] = sort
        if provider is not None:
            query["provider"] = provider
        if limit is not None:
            query["limit"] = str(limit)
        if offset is not None:
            query["offset"] = str(offset)
        return await self._get("/v1/models/leaderboard", query or None)
