from template_project.application.common.data_structure import to_data_structure
from template_project.application.common.identity_provider import IdentityProvider
from template_project.application.common.interactor import to_interactor
from template_project.application.user.entity import UserId
from template_project.application.user.profile.data_gateway import ProfileDataGateway


@to_data_structure
class GetProfileResponse:
    id: UserId
    email: str | None
    display_name: str | None
    first_name: str | None
    last_name: str | None
    avatar_url: str | None
    phone: str | None


@to_interactor
class GetProfileInteractor:
    identity_provider: IdentityProvider
    profile_data_gateway: ProfileDataGateway

    async def execute(self) -> GetProfileResponse | None:
        current_user = await self.identity_provider.get_current_user()
        profile = await self.profile_data_gateway.load_by_user_id(current_user.id)

        if not profile:
            return None

        return GetProfileResponse(
            id=profile.user_id,
            email=profile.email,
            display_name=profile.display_name,
            first_name=profile.first_name,
            last_name=profile.last_name,
            avatar_url=profile.avatar_url,
            phone=profile.phone,
        )
