package ru.myitschool.work.domain.auth

import java.util.Locale
import java.util.Locale.getDefault

class CheckPasswordFormatUseCase {
    operator fun invoke(
        textLogin: String,
        textPassword: String
    ): Boolean {
        val lowerCasePassword = textPassword.lowercase(getDefault())
        val lowerCaseLogin = textLogin.lowercase(getDefault())
        val intersect = lowerCasePassword.toList().intersect(lowerCaseLogin.toList());
        return !(textPassword.length < 8 || !textPassword.all { char ->
            char.isLetterOrDigit()
                    && ((char in 'A'..'Z')
                        || (char in 'a'..'z')
                        || char.isDigit())
                    && textPassword.count { it == char } < 3
                    && intersect.size < 3

        })
    }
}