from models.model import Model

class Scene(Model):
    def __init__(self):
        super().__init__()

    def create(self, name="", sequences=None, groups=None):
        next_id = self.get_next_id()
        self[next_id] = {
            "name": name,
            "sequences": sequences if sequences else [],
            "groups": groups if groups else []
        }
        self.save()
        return next_id

    def read(self, id):
        id_str = str(id)
        return self.get(id_str, None)
    
    def update(self, id, data):
        id_str = str(id)
        if id_str not in self:
            return False
        self[id_str].update(data)
        self.save()
        return True
    
    def delete(self, id):
        id_str = str(id)
        if id_str not in self:
            return False
        self.pop(id_str)
        self.save()
        return True
    
    def list(self):
        return list(self.keys())
