"""Guild services."""
from __future__ import annotations
from advanced_alchemy.repository import SQLAlchemyAsyncRepository, SQLAlchemyAsyncSlugRepository
from advanced_alchemy.service import ModelDictT, SQLAlchemyAsyncRepositoryService
from byte_bot.server.domain.db.models import AllowedUsersConfig, ForumConfig, GitHubConfig, Guild, SOTagsConfig
from byte_bot.server.lib import log
__all__ = (
    "AllowedUsersConfigRepository",
    "AllowedUsersConfigService",
    "ForumConfigRepository",
    "ForumConfigService",
    "GitHubConfigRepository",
    "GitHubConfigService",
    "GuildsRepository",
    "GuildsService",
    "SOTagsConfigRepository",
    "SOTagsConfigService",
)
logger = log.get_logger()
[docs]
class GuildsRepository(SQLAlchemyAsyncSlugRepository[Guild]):
    """Guilds SQLAlchemy Repository."""
    model_type = Guild 
[docs]
class GuildsService(SQLAlchemyAsyncRepositoryService[Guild]):
    """Handles basic operations for a guild."""
    repository_type = GuildsRepository
    match_fields = ["guild_id"]
[docs]
    async def to_model(self, data: ModelDictT[Guild], operation: str | None = None) -> Guild:
        """Convert data to a model.
        Args:
            data (ModelDictT[Guild]): Data to convert to a model
            operation (str | None): Operation to perform on the data
        Returns:
            Project: Converted model
        """
        return await super().to_model(data, operation) 
 
[docs]
class GitHubConfigRepository(SQLAlchemyAsyncRepository[GitHubConfig]):
    """GitHubConfig SQLAlchemy Repository."""
    model_type = GitHubConfig 
[docs]
class GitHubConfigService(SQLAlchemyAsyncRepositoryService[GitHubConfig]):
    """Handles basic operations for the guilds' GitHub config."""
    repository_type = GitHubConfigRepository
    match_fields = ["guild_id"]
[docs]
    async def to_model(self, data: ModelDictT[GitHubConfig], operation: str | None = None) -> GitHubConfig:
        """Convert data to a model.
        Args:
            data (GitHubConfig | dict[str, Any]): Data to convert to a model
            operation (str | None): Operation to perform on the data
        Returns:
            Project: Converted model
        """
        return await super().to_model(data, operation) 
 
[docs]
class AllowedUsersConfigRepository(SQLAlchemyAsyncRepository[AllowedUsersConfig]):
    """AllowedUsersConfig SQLAlchemy Repository."""
    model_type = AllowedUsersConfig 
[docs]
class AllowedUsersConfigService(SQLAlchemyAsyncRepositoryService[AllowedUsersConfig]):
    """Handles basic operations for the guilds' Allowed Users config."""
    repository_type = AllowedUsersConfigRepository
    match_fields = ["guild_id"]
[docs]
    async def to_model(self, data: ModelDictT[AllowedUsersConfig], operation: str | None = None) -> AllowedUsersConfig:
        """Convert data to a model.
        Args:
            data (AllowedUsersConfig | dict[str, Any]): Data to convert to a model
            operation (str | None): Operation to perform on the data
        Returns:
            Project: Converted model
        """
        return await super().to_model(data, operation) 
 
[docs]
class ForumConfigRepository(SQLAlchemyAsyncRepository[ForumConfig]):
    """ForumConfig SQLAlchemy Repository."""
    model_type = ForumConfig 
[docs]
class ForumConfigService(SQLAlchemyAsyncRepositoryService[ForumConfig]):
    """Handles basic operations for the guilds' Forum config."""
    repository_type = AllowedUsersConfigRepository
    match_fields = ["guild_id"]
[docs]
    async def to_model(self, data: ModelDictT[ForumConfig], operation: str | None = None) -> ForumConfig:
        """Convert data to a model.
        Args:
            data (ForumConfig | dict[str, Any]): Data to convert to a model
            operation (str | None): Operation to perform on the data
        Returns:
            Project: Converted model
        """
        return await super().to_model(data, operation)