from app.core.crud import CRUDBase
from app.models.token import BossToken
from tortoise.expressions import Q


class BossPlatform:
    """Boss直聘平台操作类"""
    
    def __init__(self):
        self.token_crud = CRUDBase(model=BossToken)
    
    async def get_tokens(self, page: int = 1, page_size: int = 10, search: Q = None):
        """获取Boss Token列表"""
        return await self.token_crud.list(page=page, page_size=page_size, search=search)
    
    async def get_token(self, token_id: int):
        """获取Boss Token详情"""
        return await self.token_crud.get(id=token_id)
    
    async def create_token(self, obj_in: dict):
        """创建Boss Token"""
        return await self.token_crud.create(obj_in)
    
    async def update_token(self, token_id: int, obj_in: dict):
        """更新Boss Token"""
        return await self.token_crud.update(id=token_id, obj_in=obj_in)
    
    async def delete_token(self, token_id: int):
        """删除Boss Token"""
        return await self.token_crud.remove(id=token_id)


# 创建token_controller实例供API路由使用
token_controller = BossPlatform()