package ru.myitschool.work.domain.auth

class CheckCodeFormatUseCase {
    operator fun invoke(
        login: String, password: String
    ): Boolean {
        val passwordList = password.toList()
        var passwordCorrect = true
        for (i in 1..(passwordList.size - 3)) {
            val s = StringBuilder().append(passwordList[i]).append(passwordList[i+1]).append(passwordList[i+2]).toString()
            if (login.contains(s)) {
                passwordCorrect = false
            }
        }
        return login.isNotEmpty() && password.length >= 8 && passwordCorrect && login.all { char ->
            char.isLetterOrDigit() && ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z') || char.isDigit())
        } && password.all({ char -> password.count { it == char } < 3 }) && password.count { it == '!' } + password.count { it == '@' } + password.count { it == '#' } + password.count { it == '"' } + password.count { it == '№' } + password.count { it == ';' } + password.count { it == '$' } + password.count { it == '%' } + password.count { it == '^' } + password.count { it == ':' } + password.count { it == '&' } + password.count { it == '?' } + password.count { it == '*' } >= 1
    }
}