"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IQuickbooksUploadItem = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
function convertNumberToString(obj) {
    let newObj = {};
    for (const prop in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, prop)) {
            if (obj[prop] === null) {
                newObj[prop] = '';
            }
            else {
                newObj[prop] = (typeof obj[prop] === 'number') ? obj[prop].toString() : obj[prop];
            }
        }
    }
    return newObj;
}
class IQuickbooksUploadItem {
    uiId = '';
    accountCode = '';
    fullName = '';
    description = '';
    companyId = null;
    constructor(item, options) {
        if (options && options.companyId) {
            item.companyId = new mongoose_1.default.Types.ObjectId(options.companyId);
        }
        item = convertNumberToString(item);
        Object.assign(this, item);
    }
    async initialize() {
        return await this.validateData();
    }
    async validateData() {
        const errors = [];
        if (!this.accountCode || this.accountCode.trim().length === 0) {
            errors.push({ accountCode: [{ error: `account code is too short` }] });
        }
        if (!this.fullName || this.fullName.trim().length === 0) {
            errors.push({ fullName: [{ error: `full name is too short` }] });
        }
        if (!this.companyId) {
            errors.push({ fullName: [{ error: `company is required` }] });
        }
        return errors;
    }
}
exports.IQuickbooksUploadItem = IQuickbooksUploadItem;
