package com.gh.gamecenter.core.callback

interface OnAccelerateListener {

    fun onStateChanged(state: AccelerateState)

    fun onProgress(progress: Int, curGamePkgName: String?, curGameZoneFlag: String?)
}

sealed class AccelerateState(val code: Int) {
    // token 过期
    val isTokenInvalid: Boolean
        get() = code == ACCT_CODE_TOKEN_EXPIRED ||
                code == ACCT_CODE_TOKEN_INVALID ||
                code == ACCT_CODE_TOKEN_EMPTY

    val isSkipError: Boolean
        get() = skipErrorCodes.any { it == code }

    val isPermissionExpired: Boolean
        get() = code == ACCT_CODE_PERMISSION_EXPIRE

    data class Normal(private val _code: Int) : AccelerateState(_code)

    data class Starting(private val _code: Int) : AccelerateState(_code)

    data class Success(val acctGameInfo: Any?, private val _code: Int) : AccelerateState(_code)

    data class Failure(private val _code: Int) : AccelerateState(_code)

    data class OkStopping(private val _code: Int) : AccelerateState(_code)

    data class ErrStopping(private val _code: Int) : AccelerateState(_code)

    companion object {
        private const val ACCT_CODE_TOKEN_EMPTY = 102
        private const val ACCT_CODE_TOKEN_EXPIRED = 200 // token过期
        private const val ACCT_CODE_TOKEN_INVALID = 201 // token无效
        private const val ACCT_CODE_PERMISSION_DENIED = 290   // 用户拒绝权限
        private const val ACCT_CODE_PERMISSION_EXPIRE = 220 // 加速时长到期
        private val skipErrorCodes = arrayOf(ACCT_CODE_PERMISSION_DENIED,ACCT_CODE_PERMISSION_EXPIRE)
    }
}