"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs-extra"));
const FactorioAnalyticsApi_1 = require("../../src/FactorioAnalyticsApi");
require('dotenv').config();
function main() {
    return __awaiter(this, void 0, void 0, function* () {
        const bpFile = '/home/overflow/Projects/factorio-analytics/factory/examples/45spm_base.bp';
        const bpStr = yield fs.readFile(bpFile, 'utf8');
        // submit a blueprint
        let source = yield FactorioAnalyticsApi_1.FactorioAnalyticsApi.submitSource(bpStr);
        console.log('Submitted source:', source);
        // submit a trial to run for this source - this will be a long-running trial!
        let longTrial = yield FactorioAnalyticsApi_1.FactorioAnalyticsApi.submitTrial({
            name: '45spm_base 3_27_2024',
            desc: 'Basic base blueprint - long test. 108k ticks, 300 tick interval, all data recorded',
            source: source,
            length: 108000,
            tickInterval: 300,
            recordItems: true,
            recordElectric: true,
            recordCircuit: true,
            recordPollution: true,
            recordSystem: true
        });
        // submit a short trial
        let shortTrial = yield FactorioAnalyticsApi_1.FactorioAnalyticsApi.submitTrial({
            //TEST GENERATING NAME FOR TRIAL name: '45spm_base 3_27_2024_short',
            //desc: 'Basic base blueprint - short test. 18k ticks, 60 tick interval, only item data',
            source: source,
            length: 36000,
            tickInterval: 60,
            recordItems: true,
            recordElectric: false,
            recordCircuit: false,
            recordPollution: false,
            recordSystem: false
        });
        // both trials above
        console.log('Submitted trials:');
        console.table([longTrial, shortTrial]);
        // let ltHandle = setInterval(async () => {
        //     try {
        //         let longTrialStatus = await FactorioAnalyticsApi.queryStatus(longTrial.execution_id)
        //         if (longTrialStatus) {
        //             console.log('Long trial status:')
        //             console.table(longTrialStatus)
        //             if (longTrialStatus.success != null) {
        //                 clearInterval(ltHandle)
        //                 longTrial = await FactorioAnalyticsApi.query('trial', longTrial.trialId)
        //             }
        //         }
        //     } catch (e) {
        //         console.log('Error querying long trial status:', e)
        //     }
        // }, 2000)
        let results = yield FactorioAnalyticsApi_1.FactorioAnalyticsApi.queryStatusOnTick(shortTrial.execution_id);
        console.table(results);
        // let stHandle = setInterval(async () => {
        //     try {
        //         let shortTrialStatus = await FactorioAnalyticsApi.queryStatus(shortTrial.execution_id)
        //         if (shortTrialStatus) {
        //             console.log('Short trial status:')
        //             console.table(shortTrialStatus)
        //             if (shortTrialStatus?.success != null) {
        //                 clearInterval(stHandle)
        //                 shortTrial = await FactorioAnalyticsApi.query('trial', shortTrial.trialId)
        //             }
        //         }
        //     } catch (e) {
        //         console.log('Error querying short trial status:', e)
        //     }
        // }, 2000)
        //let s = source.gridSize
    });
}
main().then((t) => __awaiter(void 0, void 0, void 0, function* () {
    console.log('Finished running TestPublicApi.ts');
})).catch((e) => {
    console.error(e);
});
//# sourceMappingURL=TestPublicApi.js.map