"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 __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
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 BaseController_1;
Object.defineProperty(exports, "__esModule", { value: true });
const server_1 = require("@methodus/server");
const db_1 = require("../db");
const platform_express_1 = require("@methodus/platform-express");
let BaseController = BaseController_1 = class BaseController {
    list(filter = {}, pageNumber = 1, pageSize = 10, req) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!filter) {
                filter = {};
            }
            const dbResult = db_1.DB.getPosts(filter, pageNumber, pageSize);
            const result = new server_1.MethodResult(dbResult);
            result.linkAction('get', BaseController_1, 'Post', dbResult, req.headers['host']);
            return result.apply();
        });
    }
    get(id, host = '') {
        return __awaiter(this, void 0, void 0, function* () {
            const dbResult = db_1.DB.getPosts({ id: Number(id) }, 1, 10);
            const result = new server_1.MethodResult(dbResult);
            result.linkAction('list', BaseController_1, 'Get', {}, host);
            return result.apply();
        });
    }
    // @Method(Verbs.Get, '/:player_name/desfaults')
    // public async listdefaults(@Param('player_name') player_name: any,
    //     @Body() body: any,
    //     @Headers() headers: any,
    //     @Files() files: any,
    //     @Cookies() cookies: any,
    //     @Query() query: any,
    //     @Response() res: any,
    //     @Request() req: any,
    //     @SecurityContext() securityContext: any,
    // ): Promise<any> {
    //     return new MethodResultStatus([1, 2, 3, 4, 5], 203, 5, 1);
    // }
    // @MethodPipe(Verbs.Post, '/')
    // public async create(@Files('files') files: any,
    //     @Cookies('cookies') cookies: any, @Body('name') name: string) {
    //     return new MethodResult({ name });
    // }
    read(playerId) {
        return __awaiter(this, void 0, void 0, function* () {
            return new server_1.MethodResult(playerId);
        });
    }
    getByField(field, value) {
        return __awaiter(this, void 0, void 0, function* () {
            return new server_1.MethodResult({});
        });
    }
};
__decorate([
    server_1.MethodMock({}),
    server_1.Method(platform_express_1.Verbs.Get, '/'),
    __param(0, server_1.Mapping.Query('filter')), __param(1, server_1.Mapping.Query('pageNumber')),
    __param(2, server_1.Mapping.Query('pageSize')), __param(3, server_1.Mapping.Request()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Number, Number, Object]),
    __metadata("design:returntype", Promise)
], BaseController.prototype, "list", null);
__decorate([
    server_1.Method(platform_express_1.Verbs.Get, '/:id'),
    __param(0, server_1.Mapping.Param('id')), __param(1, server_1.Mapping.Headers('host')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, String]),
    __metadata("design:returntype", Promise)
], BaseController.prototype, "get", null);
__decorate([
    server_1.Method(platform_express_1.Verbs.Get, '/get/:player_id'),
    __param(0, server_1.Mapping.Param('player_id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Promise)
], BaseController.prototype, "read", null);
__decorate([
    server_1.Method(platform_express_1.Verbs.Get, '/:field/:value'),
    __param(0, server_1.Mapping.Param('field')), __param(1, server_1.Mapping.Param('value')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Number]),
    __metadata("design:returntype", Promise)
], BaseController.prototype, "getByField", null);
BaseController = BaseController_1 = __decorate([
    server_1.MethodConfigBase('BaseController')
], BaseController);
exports.BaseController = BaseController;
//# sourceMappingURL=controller.base.js.map