/**
 * ==================================================
 * Smart Attendance System
 * AI Train Service
 * ==================================================
 * Uploads multiple student images to the
 * Python AI Training API.
 * ==================================================
 */

const fs = require("fs");
const FormData = require("form-data");

const aiClient = require("./aiClient");


class TrainService {

    /**
     * Train Student
     */
    static async train(
        studentId,
        imagePaths = []
    ) {

        const form = new FormData();

        form.append(
            "student_id",
            studentId
        );

        for (const path of imagePaths) {

            form.append(
                "images",
                fs.createReadStream(path)
            );

        }

        const response = await aiClient.post(

            "/train",

            form,

            {

                headers: form.getHeaders()

            }

        );

        return response.data;

    }

}

module.exports = TrainService;