from snek.system.service import BaseService


class DriveService(BaseService):
    
    mapper_name = "drive"

    async def get_by_user(self, user_uid):
        drives = [] 
        async for model in self.find(user_uid=user_uid):
            drives.append(model)
        return drives 

    async def get_or_create(self, user_uid):
        drives = await self.get_by_user(user_uid=user_uid)
        if len(drives) == 0:
            model = await self.new()
            model['user_uid'] = user_uid  
            await self.save(model)
            return model 
        return drives[0]
