package com.flagship.abox.manager.domain

import kotlinx.coroutines.flow.Flow

interface SessionGateway {
    fun observeSession(profileId: ProviderProfileId): Flow<Session?>

    suspend fun login(
        profileId: ProviderProfileId,
        credentials: LoginCredentials,
    ): DomainResult<Session>

    suspend fun validateSession(profileId: ProviderProfileId): DomainResult<SessionValidity>

    suspend fun logout(profileId: ProviderProfileId): DomainResult<Unit>
}

interface DeviceCatalog {
    fun observeDevices(
        profileId: ProviderProfileId,
    ): Flow<DomainResult<List<DeviceDescriptor>>>
}

interface SocketGateway {
    suspend fun getStatus(
        profileId: ProviderProfileId,
        deviceName: DeviceName,
    ): DomainResult<SocketStatus>

    suspend fun setPower(
        profileId: ProviderProfileId,
        deviceName: DeviceName,
        powerState: SocketPowerState,
    ): DomainResult<SocketStatus>
}

interface TemperatureHumidityGateway {
    suspend fun getReading(
        profileId: ProviderProfileId,
        deviceName: DeviceName,
    ): DomainResult<TemperatureHumidityReading>
}

interface InfraredGateway {
    suspend fun sendKey(
        profileId: ProviderProfileId,
        deviceName: DeviceName,
        key: String,
    ): DomainResult<Unit>

    suspend fun learnKey(
        profileId: ProviderProfileId,
        deviceName: DeviceName,
        key: String,
    ): DomainResult<Unit>

    suspend fun downloadCodes(
        profileId: ProviderProfileId,
        codes: List<InfraredCode>,
    ): DomainResult<List<InfraredCodeDownloadResult>>
}
