from snek.system.service import BaseService

class ContainerService(BaseService):
    mapper_name = "container"

    async def create(self, id, name, status, resources=None, user_uid=None, path=None, readonly=False):
        model = await self.new()
        model["id"] = id
        model["name"] = name
        model["status"] = status
        if resources:
            model["resources"] = resources
        if user_uid:
            model["user_uid"] = user_uid
        if path:
            model["path"] = path
        model["readonly"] = readonly
        if await super().save(model):
            return model
        raise Exception(f"Failed to create container: {model.errors}")

    async def get(self, id):
        return await self.mapper.get(id)

    async def update(self, model):
        return await self.mapper.update(model)

    async def delete(self, id):
        return await self.mapper.delete(id)
