package pl.firmatpp.kierowca.ui

class OtpAutoSubmitPolicy {
    private var lastSubmittedCode: String? = null

    fun shouldSubmit(code: String, loading: Boolean): Boolean {
        if (code.length < OTP_LENGTH) {
            lastSubmittedCode = null
            return false
        }

        if (loading || code.length != OTP_LENGTH || code == lastSubmittedCode) {
            return false
        }

        lastSubmittedCode = code
        return true
    }

    fun reset() {
        lastSubmittedCode = null
    }

    private companion object {
        const val OTP_LENGTH = 6
    }
}
