from dataclasses import dataclass, field
from models.base import BaseModel

@dataclass
class Child(BaseModel):
    name: str
    age: int | None = None
    tasks: list[str] = field(default_factory=list)
    rewards: list[str] = field(default_factory=list)
    points: int = 0
    image_id: str | None = None

    @classmethod
    def from_dict(cls, d: dict):
        return cls(
            name=d.get('name'),
            age=d.get('age'),
            tasks=d.get('tasks', []),
            rewards=d.get('rewards', []),
            points=d.get('points', 0),
            image_id=d.get('image_id'),
            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({
            'name': self.name,
            'age': self.age,
            'tasks': self.tasks,
            'rewards': self.rewards,
            'points': self.points,
            'image_id': self.image_id
        })
        return base
