from datetime import datetime

from bclearer_core.constants.standard_constants import (
    HR_DATE_TIME_FORMAT,
    HR_NAME_COMPONENT_DIVIDER,
)
from bclearer_core.infrastructure.session.app_run_session.bie_app_run_session_types import (
    BieAppRunSessionTypes,
)
from bclearer_core.infrastructure.session.common.session_identity_vectors import (
    AppRunSessionObjectIdentityVector,
    AppRunSessionObjectIdentityVectorPlaces,
)
from bclearer_core.infrastructure.session.common.session_objects import (
    SessionObjects,
)
from bclearer_core.infrastructure.session.os_user_session.os_user_profile_session_objects import (
    OsUserProfileSessionObjects,
)
from bclearer_orchestration_services.identification_services.b_identity_ecosystem.bie_id_creation_module.identity_vectors import (
    BieIdentityVectorBase,
)


class AppRunSessionObjects(
    SessionObjects
):
    def __init__(
        self,
        bie_app_run_session_type: BieAppRunSessionTypes,
    ):
        self.bie_app_run_session_type = (
            bie_app_run_session_type
        )

        self.owning_os_user_profile_session = (
            OsUserProfileSessionObjects()
        )

        self.app_run_session_date_time = (
            datetime.now()
        )

        self.local_hr_name = (
            self.owning_os_user_profile_session.owning_operating_system_object.base_hr_name
            + HR_NAME_COMPONENT_DIVIDER
            + self.owning_os_user_profile_session.owning_os_user_profile.base_hr_name
            + HR_NAME_COMPONENT_DIVIDER
            + self.app_run_session_date_time.strftime(
                format=HR_DATE_TIME_FORMAT
            )
        )

        identity_vector = (
            self._create_vector()
        )

        super().__init__(
            identity_vector=identity_vector,
        )

    def _create_vector(
        self,
    ) -> BieIdentityVectorBase:
        vector_places = (
            self._create_vector_places()
        )

        app_run_session_identity_vector = AppRunSessionObjectIdentityVector(
            bie_type=self.bie_app_run_session_type,
            bie_hr_name=self.local_hr_name,
            places=vector_places,
        )

        return app_run_session_identity_vector

    def _create_vector_places(
        self,
    ) -> AppRunSessionObjectIdentityVectorPlaces:
        app_run_session_identity_vector_places = AppRunSessionObjectIdentityVectorPlaces(
            app_run_session_type_bie_id=self.bie_app_run_session_type.item_bie_identity,
            owning_os_user_profile_session_bie_id=self.owning_os_user_profile_session.bie_id,
            app_run_session_date_time=self.app_run_session_date_time,
        )

        return (
            app_run_session_identity_vector_places
        )
