from dataclasses import dataclass
from models.base import BaseModel


@dataclass
class PushSubscription(BaseModel):
    user_id: str
    endpoint: str
    keys: dict  # {'p256dh': str, 'auth': str}

    @classmethod
    def from_dict(cls, d: dict) -> 'PushSubscription':
        return cls(
            user_id=d.get('user_id'),
            endpoint=d.get('endpoint'),
            keys=d.get('keys', {}),
            id=d.get('id'),
            created_at=d.get('created_at'),
            updated_at=d.get('updated_at'),
        )

    def to_dict(self) -> dict:
        base = super().to_dict()
        base.update({
            'user_id': self.user_id,
            'endpoint': self.endpoint,
            'keys': self.keys,
        })
        return base
