package de.trainingstagebuch.app.utils

import de.trainingstagebuch.app.R

object AuthInputValidator {
    private const val MIN_PASSWORD_LENGTH = 6

    fun validateLogin(email: String, password: String): Int? {
        return ValidationUtils.requireAllNotBlank(
            messageResId = R.string.error_required_login_fields,
            email,
            password
        )
    }

    fun validateRegister(email: String, password: String, confirmPassword: String): Int? {
        return ValidationUtils.requireAllNotBlank(
            messageResId = R.string.error_required_register_fields,
            email,
            password,
            confirmPassword
        ) ?: ValidationUtils.requireEquals(
            expected = password,
            actual = confirmPassword,
            messageResId = R.string.error_password_mismatch
        )
    }

    fun validateForgotPassword(email: String): Int? {
        return ValidationUtils.requireAllNotBlank(
            messageResId = R.string.error_required_email,
            email
        )
    }

    fun validateResetPassword(token: String, password: String, confirmPassword: String): Int? {
        return ValidationUtils.requireAllNotBlank(
            messageResId = R.string.error_required_reset_token,
            token
        ) ?: ValidationUtils.requireEquals(
            expected = password,
            actual = confirmPassword,
            messageResId = R.string.error_password_mismatch
        ) ?: if (password.length < MIN_PASSWORD_LENGTH) {
            R.string.error_password_too_short
        } else {
            null
        }
    }
}
