/**
 * ==========================================================
 * Smart Attendance System
 * Authentication Validator
 * ==========================================================
 */

class AuthValidator {

    /**
     * ======================================================
     * Validate Login
     * ======================================================
     */
    validateLogin(data) {

        const errors = {};

        if (!data.username || data.username.trim() === "") {

            errors.username =
                "Username is required.";

        }

        if (!data.password || data.password.trim() === "") {

            errors.password =
                "Password is required.";

        }

        return {

            valid: Object.keys(errors).length === 0,

            errors

        };

    }

    /**
     * ======================================================
     * Validate Change Password
     * ======================================================
     */
    validateChangePassword(data) {

        const errors = {};

        if (!data.currentPassword) {

            errors.currentPassword =
                "Current password is required.";

        }

        if (!data.newPassword) {

            errors.newPassword =
                "New password is required.";

        }

        if (!data.confirmPassword) {

            errors.confirmPassword =
                "Confirm password is required.";

        }

        if (

            data.newPassword &&

            data.confirmPassword &&

            data.newPassword !== data.confirmPassword

        ) {

            errors.confirmPassword =
                "Passwords do not match.";

        }

        if (

            data.newPassword &&

            data.newPassword.length < 8

        ) {

            errors.newPassword =
                "Password must be at least 8 characters.";

        }

        return {

            valid: Object.keys(errors).length === 0,

            errors

        };

    }

}

module.exports = new AuthValidator();