"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); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MembersController = void 0;
const common_1 = require("@nestjs/common");
const permission_request_util_1 = require("../../common/access-control/permission-request.util");
const current_user_decorator_1 = require("../../common/decorators/current-user.decorator");
const zod_validation_pipe_1 = require("../../common/pipes/zod-validation.pipe");
const jwt_guard_1 = require("../owner/guards/jwt.guard");
const login_throttle_guard_1 = require("../owner/guards/login-throttle.guard");
const members_dto_1 = require("./members.dto");
const members_service_1 = require("./members.service");
let MembersController = class MembersController {
    constructor(service) {
        this.service = service;
    }
    async login(data, req, res) {
        const clientIp = req.headers['x-forwarded-for']?.split(',')[0]?.trim() ||
            req.ip ||
            req.socket.remoteAddress ||
            '127.0.0.1';
        const result = await this.service.signinMember(data, clientIp);
        return res.status(common_1.HttpStatus.OK).json(result);
    }
    async create(data, owner_id, req, res) {
        const result = await this.service.createMember(data, owner_id, (0, permission_request_util_1.getPermissionContext)(req.user));
        return res.status(common_1.HttpStatus.OK).json(result);
    }
    async getAll(owner_id, dataScope, req, res) {
        const result = await this.service.getMembers(owner_id, (0, permission_request_util_1.getPermissionContext)(req.user), dataScope);
        return res.status(common_1.HttpStatus.OK).json(result);
    }
    async getByFilteres(query, owner_id, req, res) {
        const result = await this.service.getMembersByFilters(query, owner_id, (0, permission_request_util_1.getPermissionContext)(req.user));
        return res.status(common_1.HttpStatus.OK).json(result);
    }
    async findMember(memberId, owner_id, req, res) {
        const result = await this.service.getMemberById(memberId, owner_id, (0, permission_request_util_1.getPermissionContext)(req.user));
        return res.status(common_1.HttpStatus.OK).json(result);
    }
    async updateMember(data, memberId, owner_id, req, res) {
        const result = await this.service.updateMember(memberId, data, owner_id, (0, permission_request_util_1.getPermissionContext)(req.user));
        return res.status(common_1.HttpStatus.OK).json(result);
    }
    async delete(memberId, owner_id, req, res) {
        const result = await this.service.deleteMember(memberId, owner_id, (0, permission_request_util_1.getPermissionContext)(req.user));
        return res.status(common_1.HttpStatus.OK).json(result);
    }
};
exports.MembersController = MembersController;
__decorate([
    (0, common_1.UseGuards)(login_throttle_guard_1.LoginThrottlerGuard),
    (0, common_1.UsePipes)(new zod_validation_pipe_1.ZodValidationPipe(members_dto_1.signinMemberSchema)),
    (0, common_1.Post)('signin'),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.Req)()),
    __param(2, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object, Object]),
    __metadata("design:returntype", Promise)
], MembersController.prototype, "login", null);
__decorate([
    (0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
    (0, common_1.UsePipes)(new zod_validation_pipe_1.ZodValidationPipe(members_dto_1.createMemberSchema)),
    (0, common_1.Post)('create'),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, Object, Object]),
    __metadata("design:returntype", Promise)
], MembersController.prototype, "create", null);
__decorate([
    (0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
    (0, common_1.Get)('all'),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __param(1, (0, common_1.Query)('data_scope')),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object, Object]),
    __metadata("design:returntype", Promise)
], MembersController.prototype, "getAll", null);
__decorate([
    (0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
    (0, common_1.UsePipes)(new zod_validation_pipe_1.ZodValidationPipe(members_dto_1.filterMembersSchema)),
    (0, common_1.Get)('filter'),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, Object, Object]),
    __metadata("design:returntype", Promise)
], MembersController.prototype, "getByFilteres", null);
__decorate([
    (0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
    (0, common_1.Get)('find/:memberId'),
    __param(0, (0, common_1.Param)('memberId')),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object, Object]),
    __metadata("design:returntype", Promise)
], MembersController.prototype, "findMember", null);
__decorate([
    (0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
    (0, common_1.UsePipes)(new zod_validation_pipe_1.ZodValidationPipe(members_dto_1.updateMemberSchema)),
    (0, common_1.Patch)('update/:memberId'),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.Param)('memberId')),
    __param(2, (0, current_user_decorator_1.CurrentUser)()),
    __param(3, (0, common_1.Req)()),
    __param(4, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, String, Object, Object]),
    __metadata("design:returntype", Promise)
], MembersController.prototype, "updateMember", null);
__decorate([
    (0, common_1.UseGuards)(jwt_guard_1.JwtAuthGuard),
    (0, common_1.Delete)('delete/:memberId'),
    __param(0, (0, common_1.Param)('memberId')),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object, Object]),
    __metadata("design:returntype", Promise)
], MembersController.prototype, "delete", null);
exports.MembersController = MembersController = __decorate([
    (0, common_1.Controller)('members'),
    __metadata("design:paramtypes", [members_service_1.MembersService])
], MembersController);
//# sourceMappingURL=members.controller.js.map