<commit_before>package net.squanchy.service.firestore

import net.squanchy.eventdetails.domain.view.ExperienceLevel
import net.squanchy.schedule.domain.view.Event
import net.squanchy.schedule.domain.view.Place
import net.squanchy.schedule.domain.view.Track
import net.squanchy.service.firestore.model.conferenceinfo.FirestoreVenue
import net.squanchy.service.firestore.model.schedule.FirestoreEvent
import net.squanchy.service.firestore.model.schedule.FirestorePlace
import net.squanchy.service.firestore.model.schedule.FirestoreSpeaker
import net.squanchy.service.firestore.model.schedule.FirestoreTrack
import net.squanchy.speaker.domain.view.Speaker
import net.squanchy.support.lang.Checksum
import net.squanchy.support.lang.optional
import net.squanchy.venue.domain.view.Venue
import org.joda.time.DateTimeZone
import org.joda.time.LocalDateTime

fun FirestorePlace.toPlace(): Place = Place.create(id, name, floor.optional())

fun FirestoreTrack.toTrack() = Track(
    id = id,
    name = name,
    accentColor = accentColor.optional(),
    textColor = textColor.optional(),
    iconUrl = iconUrl.optional()
)

fun FirestoreSpeaker.toSpeaker(checksum: Checksum) = Speaker(
    numericId = checksum.getChecksumOf(id),
    id = id,
    name = name,
    bio = bio,
    companyName = companyName.optional(),
    companyUrl = companyUrl.optional(),
    personalUrl = personalUrl.optional(),
    photoUrl = photoUrl.optional(),
    twitterUsername = twitterUsername.optional()
)

fun FirestoreVenue.toVenue() = Venue(
    name = name,
    address = address,
    latitude = latLon.latitude,
    longitude = latLon.longitude,
    description = description,
    mapUrl = mapUrl,
    timeZone = DateTimeZone.forID(timezone)
)

fun FirestoreEvent.toEvent(checksum: Checksum, dateTime: DateTimeZone) = Event(
    id = id,
    numericId = checksum.getChecksumOf(id),
    startTime = LocalDateTime(startTime),
    endTime = LocalDateTime(endTime),
    title = title,
    place = place?.toPlace().optional(),
    experienceLevel = experienceLevel.optional().flatMap { ExperienceLevel.tryParsingFrom(it) },
    speakers = speakers.map { it.toSpeaker(checksum) },
    type = Event.Type.fromRawType(type),
    favorited = false, // TODO implement the favourites in firestore
    description = description.optional(),
    track = track?.toTrack().optional(),
    timeZone = dateTime
)<commit_msg>extract a couple more private mappers<commit_after>package net.squanchy.service.firestore

import net.squanchy.eventdetails.domain.view.ExperienceLevel
import net.squanchy.schedule.domain.view.Event
import net.squanchy.schedule.domain.view.Place
import net.squanchy.schedule.domain.view.Track
import net.squanchy.service.firestore.model.conferenceinfo.FirestoreVenue
import net.squanchy.service.firestore.model.schedule.FirestoreEvent
import net.squanchy.service.firestore.model.schedule.FirestorePlace
import net.squanchy.service.firestore.model.schedule.FirestoreSpeaker
import net.squanchy.service.firestore.model.schedule.FirestoreTrack
import net.squanchy.speaker.domain.view.Speaker
import net.squanchy.support.lang.Checksum
import net.squanchy.support.lang.optional
import net.squanchy.venue.domain.view.Venue
import org.joda.time.DateTimeZone
import org.joda.time.LocalDateTime

fun FirestorePlace.toPlace(): Place = Place.create(id, name, floor.optional())

fun FirestoreTrack.toTrack() = Track(
    id = id,
    name = name,
    accentColor = accentColor.optional(),
    textColor = textColor.optional(),
    iconUrl = iconUrl.optional()
)

fun FirestoreSpeaker.toSpeaker(checksum: Checksum) = Speaker(
    numericId = checksum.getChecksumOf(id),
    id = id,
    name = name,
    bio = bio,
    companyName = companyName.optional(),
    companyUrl = companyUrl.optional(),
    personalUrl = personalUrl.optional(),
    photoUrl = photoUrl.optional(),
    twitterUsername = twitterUsername.optional()
)

fun FirestoreVenue.toVenue() = Venue(
    name = name,
    address = address,
    latitude = latLon.latitude,
    longitude = latLon.longitude,
    description = description,
    mapUrl = mapUrl,
    timeZone = DateTimeZone.forID(timezone)
)

fun FirestoreEvent.toEvent(checksum: Checksum, dateTime: DateTimeZone) = Event(
    id = id,
    numericId = checksum.getChecksumOf(id),
    startTime = LocalDateTime(startTime),
    endTime = LocalDateTime(endTime),
    title = title,
    place = place?.toPlace().optional(),
    experienceLevel = experienceLevel.toExperienceLevel() ,
    speakers = speakers.map { it.toSpeaker(checksum) },
    type = type.toEventType(),
    favorited = false, // TODO implement the favourites in firestore
    description = description.optional(),
    track = track?.toTrack().optional(),
    timeZone = dateTime
)

private fun String?.toExperienceLevel() = ExperienceLevel.tryParsingFrom(this)
private fun String.toEventType() = Event.Type.fromRawType(this)
{'fraction_non_alphanumeric': 0.10915420847839442, 'fraction_numerical': 0.0, 'mean_word_length': 4.568985176738883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7590546', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1496, 'n_words': 272}