package com.isidroid.c23.ui.screen.render_preview

import androidx.compose.runtime.Stable
import androidx.compose.ui.unit.IntSize
import com.isidroid.core.vm.ViewEvent
import com.isidroid.core.vm.ViewSideEffect
import com.isidroid.core.vm.ViewState
import com.isidroid.rendering.constant.PrintOrientation
import com.isidroid.rendering.constant.PrintSize
import com.isidroid.rendering.model.RenderSettingsV2
import com.isidroid.spot.model.PrintProfile
import com.isidroid.spot.model.RichSpot

class RenderContract {
    sealed interface Event : ViewEvent {
        data object Click : Event
        data object OpenCopiesSettings : Event
        data object OpenPrintSizeSettings : Event
        data object OpenOrientationSettings : Event
        data object ToBack : Event
        data object OpenMap : Event
        data object OpenListProfiles : Event
        data object SendPrintJob: Event

        data class OnPageOpened(val page: Int, val containerSize: IntSize?) : Event
        data class UpdateRenderSettings(
            @PrintSize val size: Int? = null,
            @PrintOrientation val orientation: Int? = null,
            val increaseCopy: Boolean? = null,
            val page: Int = -1
        ) : Event

        data class ChangePrintProfile(val profileId: String?, val page: Int? = null) : Event
    }

    sealed interface Effect : ViewSideEffect {
        sealed interface Navigation : Effect {
            data object ToSelectContent: Navigation
            data object ToMap : Navigation
            data object ToBack : Navigation
            data class ToDetails(val jobId: String): Navigation
        }
    }

    @Stable
    data class State(
        val rendering: Boolean = false,
        val renderSettings: RenderSettingsV2 = RenderSettingsV2(),
        val printProfile: PrintProfile? = null,
        val renderSeed: Int = 0,
        @PrintSize val openPrintSize: Int? = null,
        @PrintOrientation val openOrientation: Int? = null,
        val openCopies: Int? = null,
        var richSpot: RichSpot? = null,
        val spotHasNoPrintProfiles: Boolean = false,
        val printProfilesSelector: List<PrintProfile>? = null,
        val pageCount: Int = 0,
        val error: Throwable? = null,
        val disablePrintButton: Boolean = false
    ) : ViewState
}