from snek.system.service import BaseService


class DriveItemService(BaseService):

    mapper_name = "drive_item"

    async def create(self, drive_uid, name, path, type_, size):
        model = await self.new()
        model["drive_uid"] = drive_uid
        model["name"] = name
        model["path"] = str(path)
        model["extension"] = str(name).split(".")[-1]
        model["file_type"] = type_
        model["file_size"] = size
        if await self.save(model):
            return model
        errors = await model.errors
        print("XXXXXXXXXX")
        raise Exception(f"Failed to create drive item: {errors}.")
