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

class AttendanceValidator {

    /**
     * ======================================================
     * Mark Attendance Validation
     * ======================================================
     */
    static validateAttendance(data) {

        const errors = [];

        if (
            data.face_student_id === undefined ||
            data.face_student_id === null ||
            data.face_student_id === ""
        ) {

            errors.push({

                field: "face_student_id",

                message: "Face Student ID is required."

            });

        }

        if (
            !data.nfc_uid ||
            typeof data.nfc_uid !== "string" ||
            data.nfc_uid.trim() === ""
        ) {

            errors.push({

                field: "nfc_uid",

                message: "NFC UID is required."

            });

        }

        return {

            valid: errors.length === 0,

            errors

        };

    }

    /**
     * ======================================================
     * Checkout Validation
     * ======================================================
     */
    static validateCheckout(data) {

        const errors = [];

        if (
            data.student_id === undefined ||
            data.student_id === null ||
            data.student_id === ""
        ) {

            errors.push({

                field: "student_id",

                message: "Student ID is required."

            });

        }

        return {

            valid: errors.length === 0,

            errors

        };

    }

    /**
     * ======================================================
     * Monthly Report Validation
     * ======================================================
     */
    static validateMonthlyReport(data) {

        const errors = [];

        if (!data.year) {

            errors.push({

                field: "year",

                message: "Year is required."

            });

        }

        if (!data.month) {

            errors.push({

                field: "month",

                message: "Month is required."

            });

        }

        if (
            data.month &&
            (
                Number(data.month) < 1 ||
                Number(data.month) > 12
            )
        ) {

            errors.push({

                field: "month",

                message: "Month must be between 1 and 12."

            });

        }

        return {

            valid: errors.length === 0,

            errors

        };

    }

}

module.exports = AttendanceValidator;