package ru.fincode.tsudesk.feature.schedule.presentation.screen

import ru.fincode.tsudesk.core.common.model.DataResult
import ru.fincode.tsudesk.feature.schedule.domain.model.ScheduleEntity
import ru.fincode.tsudesk.feature.schedule.domain.model.ScheduleType
import ru.fincode.tsudesk.feature.schedule.presentation.util.buildDayStrip
import ru.fincode.tsudesk.feature.schedule.presentation.util.todayString

enum class ScheduleViewMode { DAY, WEEK }

data class ScheduleUiState(
    val isLoading: Boolean = false,
    val error: String? = null,

    val selectedType: ScheduleType = ScheduleType.Group("220631"),

    val groupInput: String = "220631",
    val recentGroups: List<String> = listOf("220631", "220632", "220633"),
    val isGroupMenuExpanded: Boolean = false,

    val viewMode: ScheduleViewMode = ScheduleViewMode.DAY,

    val selectedDate: String = todayString(),
    val dayStrip: List<String> = buildDayStrip(todayString()),

    val raw: DataResult<ScheduleEntity>? = null,

    val dayLessons: List<UiLesson> = emptyList(),
    val weekGrouped: List<UiWeekDay> = emptyList(),
)

sealed interface ScheduleIntent {
    data class ChangeGroupInput(val value: String) : ScheduleIntent
    data object ApplyGroup : ScheduleIntent
    data class SetGroupMenuExpanded(val expanded: Boolean) : ScheduleIntent
    data class SelectRecentGroup(val number: String) : ScheduleIntent
    data class RemoveRecentGroup(val number: String) : ScheduleIntent

    data class SelectDate(val date: String) : ScheduleIntent
    data class SetViewMode(val mode: ScheduleViewMode) : ScheduleIntent

    data object Retry : ScheduleIntent
}

data class UiLesson(
    val id: String,
    val time: String,
    val title: String,
    val teacher: String,
    val room: String,
    val badgeText: String,
    val badgeKind: BadgeKind,
    val isNow: Boolean,
)

enum class BadgeKind { INFO, PRIMARY, LAB, MUTED }

data class UiWeekDay(
    val date: String,
    val title: String,
    val lessons: List<UiLesson>,
)