def METHOD_NAME(self, metadata: EventPayloadMetadata, source: Entity,
             session: Union[Optional[Entity], Optional[Session]],
             profile: Optional[Entity],
             has_profile: bool) -> Event:
    meta = EventMetadata(**metadata.dict())
    meta.profile_less = not has_profile
    meta.instance = Entity(id=ApiInstance().id)
    if self.time.insert:
        meta.time.insert = self.time.insert
    if self.time.create:
        meta.time.create = self.time.create
    if isinstance(session, Session):
        try:
            title = self.context['page']['title']
        except KeyError:
            title = None
        try:
            url = self.context['page']['url']
        except KeyError:
            url = None
        try:
            referer = self.context['page']['referer']['host']
        except KeyError:
            referer = None
        hit = Hit(
            name=title,
            url=url,
            referer=referer
        )
        event_type = self.type.strip()
        event = Event(id=str(uuid4()),
                      name=capitalize_event_type_id(event_type),
                      metadata=meta,
                      session=self._get_event_session(session),
                      profile=get_entity(profile),  # profile can be None when profile_less event.
                      type=event_type,
                      os=session.os,
                      app=session.app,
                      device=session.device,
                      hit=hit,
                      utm=session.utm,
                      properties=self.properties,
                      source=source,  # Entity
                      config=self.options,
                      context=self.context,
                      operation=RecordFlag(new=True),
                      tags=Tags(values=tuple(self.tags), count=len(self.tags))
                      )
    else:
        event_type = self.type.strip()
        event = Event(id=str(uuid4()),
                      name=capitalize_event_type_id(event_type),
                      metadata=meta,
                      session=self._get_event_session(session),
                      profile=get_entity(profile),  # profile can be None when profile_less event.
                      type=event_type,
                      properties=self.properties,
                      source=source,  # Entity
                      config=self.options,
                      context=self.context,
                      operation=RecordFlag(new=True),
                      tags=Tags(values=tuple(self.tags), count=len(self.tags))
                      )
    return event