/**
 * ==================================================
 * Smart Attendance System
 * Device Validator
 * ==================================================
 * Validates device request payloads.
 * ==================================================
 */

class DeviceValidator {

    // ==========================================
    // Validate Device Registration
    // ==========================================

    static create(data) {

        const errors = [];

        if (

            !data.device_id ||

            data.device_id.trim() === ""

        ) {

            errors.push(

                "Device ID is required."

            );

        }

        if (

            !data.device_name ||

            data.device_name.trim() === ""

        ) {

            errors.push(

                "Device Name is required."

            );

        }

        if (

            !data.device_type ||

            data.device_type.trim() === ""

        ) {

            errors.push(

                "Device Type is required."

            );

        }

        if (

            data.device_type &&

            ![

                "ESP32_CAM",

                "ESP32_NFC",

                "ESP32_CAM_NFC"

            ].includes(data.device_type)

        ) {

            errors.push(

                "Invalid Device Type."

            );

        }

        return {

            valid:

                errors.length === 0,

            errors

        };

    }

    // ==========================================
    // Validate Device Update
    // ==========================================

    static update(data) {

        return this.create(data);

    }

    // ==========================================
    // Validate Device Verification
    // ==========================================

    static verify(data) {

        const errors = [];

        if (

            !data.device_id ||

            data.device_id.trim() === ""

        ) {

            errors.push(

                "Device ID is required."

            );

        }

        if (

            !data.api_key ||

            data.api_key.trim() === ""

        ) {

            errors.push(

                "API Key is required."

            );

        }

        return {

            valid:

                errors.length === 0,

            errors

        };

    }

}

module.exports = DeviceValidator;