from typing import Sequence from sqlalchemy import Select, select from src.core.services.base import BaseService from src.enums import ServiceType from ..models import ServiceAccount, SpotifyApiKey __all__ = ["ServiceAccountService"] class ServiceAccountService(BaseService[ServiceAccount]): model = ServiceAccount def _get_credentials_query(self, app_id: int, service_type: ServiceType) -> Select: return ( select( self.model.refresh_token, self.model.access_token, self.model.expires_in, SpotifyApiKey.client_id, SpotifyApiKey.client_secret, ) .outerjoin(self.model.spotify_api_key) .where(self.model.application_id == app_id, self.model.service_type == service_type) ) def select_for_app(self, app_id: int) -> Sequence[ServiceAccount]: stmt = select(self.model).where(self.model.application_id == app_id) return self._select_many(stmt) def select_by_user_id(self, *user_id: str) -> Sequence[ServiceAccount]: stmt = select(self.model).where(self.model.user_identifier.in_(user_id)) return self._select_many(stmt)