from dataclasses import dataclass
from models.base import BaseModel


@dataclass
class RoutineItem(BaseModel):
    routine_id: str
    name: str
    image_id: str | None = None
    order: int = 0

    @classmethod
    def from_dict(cls, d: dict):
        return cls(
            routine_id=d.get('routine_id'),
            name=d.get('name'),
            image_id=d.get('image_id'),
            order=d.get('order', 0),
            id=d.get('id'),
            created_at=d.get('created_at'),
            updated_at=d.get('updated_at')
        )

    def to_dict(self):
        base = super().to_dict()
        base.update({
            'routine_id': self.routine_id,
            'name': self.name,
            'image_id': self.image_id,
            'order': self.order
        })
        return base
