"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Setting_1 = __importDefault(require("../models/Setting"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
function loadSettings() {
    return __awaiter(this, void 0, void 0, function* () {
        const setting = yield Setting_1.default.findAll({});
        if (setting) {
            let sett = setting.map((s) => {
                return { key: s.key, value: s.value };
            });
            try {
                const keyFilename = path_1.default.join(os_1.default.tmpdir(), `whaticket_settings.json`);
                const jsonSettings = JSON.stringify(sett, null, 2);
                fs_1.default.writeFileSync(keyFilename, jsonSettings);
                console.log(`Settings saved to ${keyFilename}`);
            }
            catch (err) {
                console.error("Error saving Settings to file:", err);
            }
        }
    });
}
exports.default = loadSettings;
