"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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handle_request = void 0;
const debugger_1 = require("./debugger");
const types_1 = require("./types");
function handle_request(request) {
    return __awaiter(this, void 0, void 0, function* () {
        const debugger_instance = debugger_1.Debugger.Instance;
        if (request.command !== types_1.Command.Initialize && !debugger_instance.initialized) {
            throw new Error(`Debugger is not initialized, request: ${request}`);
        }
        let body = null;
        return new Promise((resolve, _) => __awaiter(this, void 0, void 0, function* () {
            switch (request.command) {
                case types_1.Command.Initialize:
                    yield debugger_instance.initialize(request.arguments);
                    break;
                case types_1.Command.StepInto:
                    yield debugger_instance.stepInto();
                    body = debugger_instance.currentLocation();
                    break;
                case types_1.Command.StepNext:
                    yield debugger_instance.stepNext();
                    body = debugger_instance.currentLocation();
                    break;
                case types_1.Command.StepOut:
                    yield debugger_instance.stepOut();
                    body = debugger_instance.currentLocation();
                    break;
                case types_1.Command.StepInstruction:
                    yield debugger_instance.advance();
                    body = debugger_instance.currentLocation();
                    break;
                case types_1.Command.StepOver:
                    yield debugger_instance.stepOver();
                    body = debugger_instance.currentLocation();
                    break;
                case types_1.Command.AddBreakpoint:
                    yield debugger_instance.addBreakpoint(request.arguments);
                    break;
                case types_1.Command.RemoveBreakpoint:
                    yield debugger_instance.removeBreakpoint(request.arguments);
                    break;
                case types_1.Command.RemoveAllBreakpoints:
                    yield debugger_instance.removeAllBreakpoints();
                    break;
                case types_1.Command.ContinueUntilBreakpoint:
                    yield debugger_instance.continueUntilBreakpoint();
                    body = debugger_instance.currentLocation();
                    break;
                case types_1.Command.Variables:
                    body = yield debugger_instance.variables();
                    break;
                case types_1.Command.Stacktrace:
                    body = debugger_instance.stackTrace();
                    break;
                default:
                    break;
            }
            resolve({
                command: request.command,
                request_seq: request.seq,
                success: true,
                body: body,
                seq: request.seq,
                type: 'response'
            });
        }));
    });
}
exports.handle_request = handle_request;
//# sourceMappingURL=request-handler.js.map