"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.GatesController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const client_1 = require("@prisma/client");
const require_role_decorator_1 = require("../auth/require-role.decorator");
const current_user_decorator_1 = require("../common/current-user.decorator");
const swagger_docs_1 = require("../common/swagger-docs");
const feature_catalog_1 = require("../features/feature-catalog");
const require_feature_decorator_1 = require("../features/require-feature.decorator");
const gate_dto_1 = require("./dto/gate.dto");
const gates_service_1 = require("./gates.service");
let GatesController = class GatesController {
    gatesService;
    constructor(gatesService) {
        this.gatesService = gatesService;
    }
    findAll(user, estateId) {
        return this.gatesService.findAll(user, estateId);
    }
    create(dto, user) {
        return this.gatesService.create(dto, user);
    }
    update(id, dto, user) {
        return this.gatesService.update(id, dto, user);
    }
};
exports.GatesController = GatesController;
__decorate([
    (0, common_1.Get)(),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.ESTATE_ADMIN, client_1.UserRole.SECURITY_SUPERVISOR, client_1.UserRole.GUARD),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.GATES_VIEW),
    (0, swagger_1.ApiOperation)({ summary: 'List estate gates', description: 'Returns gates in the current estate scope with guard and session counts.' }),
    (0, swagger_1.ApiQuery)({ name: 'estateId', required: false, example: swagger_docs_1.ESTATE_ID_EXAMPLE }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Gates returned.' }),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __param(1, (0, common_1.Query)('estateId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", void 0)
], GatesController.prototype, "findAll", null);
__decorate([
    (0, common_1.Post)(),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.ESTATE_ADMIN),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.GATES_MANAGE),
    (0, swagger_1.ApiOperation)({ summary: 'Create gate', description: 'Creates a gate if the estate subscription plan allows another gate.' }),
    (0, swagger_1.ApiBody)({ type: gate_dto_1.CreateGateDto }),
    (0, swagger_1.ApiResponse)({ status: 201, description: 'Gate created.' }),
    (0, swagger_docs_1.ApiValidationError)(),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [gate_dto_1.CreateGateDto, Object]),
    __metadata("design:returntype", void 0)
], GatesController.prototype, "create", null);
__decorate([
    (0, common_1.Patch)(':id'),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.ESTATE_ADMIN),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.GATES_MANAGE),
    (0, swagger_1.ApiOperation)({ summary: 'Update gate', description: 'Updates gate name, type, description, status, or metadata.' }),
    (0, swagger_1.ApiParam)({ name: 'id', example: 'gate-uuid' }),
    (0, swagger_1.ApiBody)({ type: gate_dto_1.UpdateGateDto }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Gate updated.' }),
    (0, swagger_docs_1.ApiNotFoundError)('Gate'),
    (0, swagger_docs_1.ApiValidationError)(),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, gate_dto_1.UpdateGateDto, Object]),
    __metadata("design:returntype", void 0)
], GatesController.prototype, "update", null);
exports.GatesController = GatesController = __decorate([
    (0, swagger_1.ApiTags)('Gates'),
    (0, swagger_docs_1.ApiProtectedEndpoint)(),
    (0, common_1.Controller)({ path: 'gates', version: '1' }),
    __metadata("design:paramtypes", [gates_service_1.GatesService])
], GatesController);
//# sourceMappingURL=gates.controller.js.map