package no.svorka.mcms.core

/**
 * Versioned endpoint paths (relative to `baseUrl`). IDs are kept RAW here — the
 * URL builder in [ApiClient] percent-encodes the whole path exactly once.
 * Pre-encoding double-encoded MAC colons (`:` → `%3A` → `%253A`), which MCMS
 * rejected as an invalid id.
 *
 * The `/v1` vs `/v3` prefix is fixed per endpoint per docs/MCMS_API.md §4 — the
 * two versions serve different resources and are NOT interchangeable, so there is
 * no global version switch. Endpoints not in the §4 table are marked "inferred".
 */
sealed class McmsEndpoint {
    data object Authenticate : McmsEndpoint()
    data object Logout : McmsEndpoint()
    data object DatabaseSelection : McmsEndpoint()
    data object Version : McmsEndpoint()

    data object ControllerConfigs : McmsEndpoint()
    data class ControllerConfig(val id: String) : McmsEndpoint()
    data class ControllerStats(val id: String) : McmsEndpoint()
    data class ControllerLogs(val id: String) : McmsEndpoint()

    data object OltConfigs : McmsEndpoint()
    data class OltConfig(val id: String) : McmsEndpoint()
    data object OltStates : McmsEndpoint()
    data class OltState(val id: String) : McmsEndpoint()
    data class OltStats(val id: String) : McmsEndpoint()
    data class OltLogs(val id: String) : McmsEndpoint()
    data class OltReset(val id: String) : McmsEndpoint()

    data object OnuConfigs : McmsEndpoint()
    data class OnuConfig(val id: String) : McmsEndpoint()
    data object OnuStates : McmsEndpoint()
    data class OnuState(val id: String) : McmsEndpoint()
    data class OnuStats(val id: String) : McmsEndpoint()
    data class OnuLogs(val id: String) : McmsEndpoint()
    data object OnuAlarmHistories : McmsEndpoint()
    data object OnuCpeStates : McmsEndpoint()
    data class OnuReset(val id: String) : McmsEndpoint()
    data object OnuFirmwareFiles : McmsEndpoint()
    data class OnuCpe(val id: String) : McmsEndpoint()   // versionless web helper

    fun path(): String = when (this) {
        Authenticate -> "/v1/users/authenticate/"            // §4
        Logout -> "/v1/users/logout/"                        // §4
        DatabaseSelection -> "/v1/databases/selection/"      // §4
        Version -> "/v1/ponmgr/version/"                     // inferred (probe)

        ControllerConfigs -> "/v1/controllers/configs/"      // inferred (non-fatal, runCatching)
        is ControllerConfig -> "/v1/controllers/configs/$id/"
        is ControllerStats -> "/v1/controllers/stats/$id/"
        is ControllerLogs -> "/v1/controllers/logs/$id/"

        OltConfigs -> "/v3/olts/configs/"                    // inferred: configs-list family is v3 (cf. ONU)
        is OltConfig -> "/v1/olts/configs/$id/"              // inferred: single config is v1 (cf. ONU)
        OltStates -> "/v3/olts/states/"                      // §4
        is OltState -> "/v3/olts/states/$id/"                // inferred: states family is v3
        is OltStats -> "/v1/olts/stats/$id/"                 // §4
        is OltLogs -> "/v1/olts/logs/$id/"                   // §4
        is OltReset -> "/v1/olts/$id/reset/"                 // inferred (prior default)

        OnuConfigs -> "/v3/onus/configs/"                    // §4
        is OnuConfig -> "/v1/onus/configs/$id/"              // §4
        OnuStates -> "/v3/onus/states/"                      // §4
        is OnuState -> "/v3/onus/states/$id/"                // §4
        is OnuStats -> "/v1/onus/stats/$id/"                 // §4
        is OnuLogs -> "/v1/onus/logs/$id/"                   // §4
        OnuAlarmHistories -> "/v1/onus/alarm-histories/"     // inferred (non-fatal, runCatching)
        OnuCpeStates -> "/v1/onus/cpe-states/"               // §4
        is OnuReset -> "/v1/onus/$id/reset/"                 // inferred (prior default)
        OnuFirmwareFiles -> "/v1/files/onu-firmware/"        // §4
        is OnuCpe -> "/cpe/onu/$id/"                          // versionless web helper
    }
}
