from datetime import datetime
from typing import Dict, Optional
from app.models import UserEntity, UserResponseModel
from app.schemas import RegisterSchema


class UserMapper:
    @staticmethod
    def from_google_payload(
        google_id: str, email: str, payload: Dict[str, Optional[str]]
    ) -> UserEntity:
        return UserEntity(
            google_id=google_id,
            email=email,
            name=payload.get("name"),
            pic_url=payload.get("picture"),
            birth_date=None,
            phone=None,
            role="user",
            is_active=True,
            address=None,
            created_at=datetime.now(),
            updated_at=datetime.now(),
            verification_token=None,
        )

    @staticmethod
    def from_register(data: RegisterSchema) -> UserEntity:
        return UserEntity(
            email=data.email,
            password=data.password,
            name=data.name,
            birth_date=datetime.strptime(data.birth_date, "%d-%m-%Y").date(),
            phone=data.phone,
            role="user",
            is_active=False,
            address=None,
            created_at=datetime.now(),
            updated_at=datetime.now(),
            verification_token=None,
        )

    @staticmethod
    def user_entity_to_response(user: UserEntity) -> UserResponseModel:
        print(str(user.id))
        return UserResponseModel(
            _id=str(user.id) if user.id else None,
            google_id=user.google_id,
            email=user.email,
            name=user.name,
            birth_date=user.birth_date,
            pic_url=user.pic_url,
            phone=user.phone,
            locale=user.locale,
            # created_at=user.created_at,
            # updated_at=user.updated_at,
        )
