package app.furmeet.events.system.schedule.abstractDataTypes.dataholder

import app.furmeet.events.system.helper.Language
import app.furmeet.events.system.helper.solved
import app.furmeet.events.system.schedule.abstractDataTypes.GregorianCalendarRange
import app.furmeet.events.system.schedule.abstractDataTypes.convention.Event
import app.furmeet.events.system.schedule.abstractDataTypes.convention.Place
import app.furmeet.events.system.schedule.abstractDataTypes.convention.Tag
import app.furmeet.events.system.schedule.abstractDataTypes.managed.AttendeeConFavorite

class PeekableEvent(
        val title: Map<Language, String>,
        val timeRange: GregorianCalendarRange,
        val subtitles: Map<Language, String>?,
        val descriptions: Map<Language, String>?,
        val places: List<Place>?,
        val language: Language?,
        val tags: List<Tag>?,
        val id: String?
) {
    fun similarEnough(favorite: AttendeeConFavorite): Boolean =
            title.solved == favorite.getString()
                    && timeRange == favorite.timeRange

    constructor(
            attendeeConFavorite: AttendeeConFavorite
    ) : this(
            FakeMap(attendeeConFavorite.getString()),
            attendeeConFavorite.timeRange,
            FakeMap(attendeeConFavorite.getSecondaryString()),
            null,
            null,
            null,
            null,
            null
    )

    constructor(
            event: Event
    ) : this(
            event.titles,
            event.timeRange,
            event.subtitles,
            event.descriptions,
            event.places,
            event.language,
            event.tags,
            event.uuid
    )

    override fun equals(other: Any?): Boolean {
        return when (other) {
            null -> false
            is PeekableEvent ->
                this.title == other.title &&
                        this.timeRange == other.timeRange &&
                        this.subtitles == other.subtitles &&
                        this.descriptions == other.descriptions &&
                        this.places == other.places &&
                        this.language == other.language &&
                        this.tags == other.tags &&
                        this.id == other.id
            else -> super.equals(other)
        }
    }

    override fun hashCode(): Int {
        var result = title.hashCode()
        result = 31 * result + timeRange.hashCode()
        result = 31 * result + (subtitles?.hashCode() ?: 0)
        result = 31 * result + (descriptions?.hashCode() ?: 0)
        result = 31 * result + (places?.hashCode() ?: 0)
        result = 31 * result + (language?.hashCode() ?: 0)
        result = 31 * result + (tags?.hashCode() ?: 0)
        result = 31 * result + (id?.hashCode() ?: 0)
        return result
    }

    val isCustom get() = id.isNullOrBlank()
}