# python
from dataclasses import dataclass
from models.base import BaseModel

@dataclass
class Image(BaseModel):
    type: int
    extension: str
    permanent: bool = False
    user: str | None = None

    @classmethod
    def from_dict(cls, d: dict):
        # Supports overriding base fields (id, created_at, updated_at) if present
        return cls(
            type=d.get('type'),
            extension=d.get('extension'),
            permanent=d.get('permanent', False),
            id=d.get('id'),
            created_at=d.get('created_at'),
            updated_at=d.get('updated_at'),
            user=d.get('user')
        )

    def to_dict(self):
        base = super().to_dict()
        base.update({
            'type': self.type,
            'permanent': self.permanent,
            'extension': self.extension,
            'user': self.user
        })
        return base
