from models.model import Model

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

    def create(self, group_name="", preset_names=None):
        next_id = self.get_next_id()
        self[next_id] = {
            "group_name": group_name,
            "presets": preset_names if preset_names else [],
            "sequence_duration": 3000,  # Duration per preset in ms
            "sequence_transition": 500,  # Transition time in ms
            "sequence_loop": False,
            "sequence_repeat_count": 0,  # 0 = infinite
            "sequence_active": False,
            "sequence_index": 0,
            "sequence_start_time": 0
        }
        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())
