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

@dataclass
class User(BaseModel):
    first_name: str
    last_name: str
    email: str
    password: str  # In production, this should be hashed
    verified: bool = False
    verify_token: str | None = None
    verify_token_created: str | None = None
    reset_token: str | None = None
    reset_token_created: str | None = None
    image_id: str | None = None
    pin: str = ''
    pin_setup_code: str = ''
    pin_setup_code_created: str | None = None
    marked_for_deletion: bool = False
    marked_for_deletion_at: str | None = None
    deletion_in_progress: bool = False
    deletion_attempted_at: str | None = None
    role: str = 'user'
    token_version: int = 0
    timezone: str | None = None
    email_digest_enabled: bool = True
    push_notifications_enabled: bool = True

    @classmethod
    def from_dict(cls, d: dict):
        return cls(
            first_name=d.get('first_name'),
            last_name=d.get('last_name'),
            email=d.get('email'),
            password=d.get('password'),
            verified=d.get('verified', False),
            verify_token=d.get('verify_token'),
            verify_token_created=d.get('verify_token_created'),
            reset_token=d.get('reset_token'),
            reset_token_created=d.get('reset_token_created'),
            image_id=d.get('image_id'),
            pin=d.get('pin', ''),
            pin_setup_code=d.get('pin_setup_code', ''),
            pin_setup_code_created=d.get('pin_setup_code_created'),
            marked_for_deletion=d.get('marked_for_deletion', False),
            marked_for_deletion_at=d.get('marked_for_deletion_at'),
            deletion_in_progress=d.get('deletion_in_progress', False),
            deletion_attempted_at=d.get('deletion_attempted_at'),
            role=d.get('role', 'user'),
            token_version=d.get('token_version', 0),
            timezone=d.get('timezone'),
            email_digest_enabled=d.get('email_digest_enabled', True),
            push_notifications_enabled=d.get('push_notifications_enabled', True),
            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({
            'first_name': self.first_name,
            'last_name': self.last_name,
            'email': self.email,
            'password': self.password,
            'verified': self.verified,
            'verify_token': self.verify_token,
            'verify_token_created': self.verify_token_created,
            'reset_token': self.reset_token,
            'reset_token_created': self.reset_token_created,
            'image_id': self.image_id,
            'pin': self.pin,
            'pin_setup_code': self.pin_setup_code,
            'pin_setup_code_created': self.pin_setup_code_created,
            'marked_for_deletion': self.marked_for_deletion,
            'marked_for_deletion_at': self.marked_for_deletion_at,
            'deletion_in_progress': self.deletion_in_progress,
            'deletion_attempted_at': self.deletion_attempted_at,
            'role': self.role,
            'token_version': self.token_version,
            'timezone': self.timezone,
            'email_digest_enabled': self.email_digest_enabled,
            'push_notifications_enabled': self.push_notifications_enabled,
        })
        return base
