const xlsx = require('node-xlsx');
const ContactPojo = require("../models/ContactPojo");

class ExcelUtil {

    readContacts(pathToExcelFile) {
        let workSheetsFromFile = xlsx.parse(pathToExcelFile);
        let contactList = [];
        workSheetsFromFile[0].data.forEach(
            (info, index, list) => {
                if (index > 0 && info.length > 0) {
                    // console.log(info)
                    if (info[0].includes("Aijing")){
                        console.log("found");
                    }
                    let name = info[0].trim().split(" ")
                    let firstName = name[1];
                    let lastName = name[0];
                    let phoneNumber = info[1];
                    let passportNumber = info[2];
                    let mail = info[3];
                    let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail);
                    contactList.push(newContact);
                }
            }
        )
        return contactList;
    }
}

module.exports = ExcelUtil
