"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const typedi_1 = require("typedi");
const services_1 = require("../../services");
/**
 * Created by tsxuehu on 4/11/17.
 */
/**
 * 数据文件相关api
 */
let MockDataController = class MockDataController {
    regist(router) {
        // 获取mock数据列表
        router.get('/data/getdatalist', (ctx) => __awaiter(this, void 0, void 0, function* () {
            const userId = ctx.userId;
            const dataList = yield this.mockDataService.getMockDataList(userId);
            ctx.body = {
                code: 0,
                data: dataList,
            };
        }));
        // 保存数据列表
        router.post('/data/savedatalist', ctx => {
            const userId = ctx.userId;
            this.mockDataService.saveMockDataList(userId, ctx.request.body);
            ctx.body = {
                code: 0,
            };
        });
        // 读取数据文件
        router.get('/data/getdatafile', (ctx) => __awaiter(this, void 0, void 0, function* () {
            const userId = ctx.userId;
            const content = yield this.mockDataService.getDataFileContent(userId, ctx.query.id);
            ctx.body = {
                code: 0,
                data: content,
            };
        }));
        // 保存数据文件
        router.post('/data/savedatafile', (ctx) => __awaiter(this, void 0, void 0, function* () {
            const userId = ctx.userId;
            yield this.mockDataService.saveDataFileContent(userId, ctx.query.id, ctx.request.body.content);
            ctx.body = {
                code: 0,
            };
        }));
        // 从http请求日志中保存 mock 数据
        router.post('/data/savedatafromtraffic', (ctx) => __awaiter(this, void 0, void 0, function* () {
            const userId = ctx.userId;
            const content = yield this.httpTrafficService.getResponseBody(userId, ctx.request.body.reqid);
            // 获取数据文件内容 在保存
            yield this.mockDataService.saveDataEntryFromTraffic(userId, ctx.request.body.id, ctx.request.body.name, ctx.request.body.contenttype, content);
            ctx.body = {
                code: 0,
            };
        }));
    }
};
__decorate([
    typedi_1.Inject(),
    __metadata("design:type", services_1.MockDataService)
], MockDataController.prototype, "mockDataService", void 0);
__decorate([
    typedi_1.Inject(),
    __metadata("design:type", services_1.HttpTrafficService)
], MockDataController.prototype, "httpTrafficService", void 0);
MockDataController = __decorate([
    typedi_1.Service()
], MockDataController);
exports.MockDataController = MockDataController;
//# sourceMappingURL=mockData.js.map