"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.RequestsController = 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 request_dto_1 = require("./dto/request.dto");
const requests_service_1 = require("./requests.service");
let RequestsController = class RequestsController {
    requests;
    constructor(requests) {
        this.requests = requests;
    }
    getOptions() {
        return this.requests.getOptions();
    }
    findAll(user, estateId, residentId, status) {
        return this.requests.findAll(user, estateId, residentId, status);
    }
    create(dto, user) {
        return this.requests.create(dto, user);
    }
    respond(id, dto, user) {
        return this.requests.respond(id, dto, user);
    }
};
exports.RequestsController = RequestsController;
__decorate([
    (0, common_1.Get)('options'),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.ESTATE_ADMIN, client_1.UserRole.SECURITY_SUPERVISOR, client_1.UserRole.GUARD, client_1.UserRole.RESIDENT),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.REQUESTS_VIEW),
    (0, swagger_1.ApiOperation)({
        summary: 'List request form options',
        description: 'Returns the resident request categories, priority options, expected fields, and photo-upload rule used by MobileApp request screens.'
    }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Request form options returned.' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], RequestsController.prototype, "getOptions", null);
__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, client_1.UserRole.RESIDENT),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.REQUESTS_VIEW),
    (0, swagger_1.ApiOperation)({
        summary: 'List requests and complaints',
        description: 'Residents see their own requests. Security and estate admins see requests in their estate scope.'
    }),
    (0, swagger_1.ApiQuery)({ name: 'estateId', required: false, example: swagger_docs_1.ESTATE_ID_EXAMPLE }),
    (0, swagger_1.ApiQuery)({ name: 'residentId', required: false, example: swagger_docs_1.RESIDENT_ID_EXAMPLE }),
    (0, swagger_1.ApiQuery)({ name: 'status', required: false, enum: client_1.ResidentRequestStatus }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Requests returned.' }),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __param(1, (0, common_1.Query)('estateId')),
    __param(2, (0, common_1.Query)('residentId')),
    __param(3, (0, common_1.Query)('status')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, String, String]),
    __metadata("design:returntype", void 0)
], RequestsController.prototype, "findAll", null);
__decorate([
    (0, common_1.Post)(),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.RESIDENT, client_1.UserRole.ESTATE_ADMIN, client_1.UserRole.SECURITY_SUPERVISOR),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.REQUESTS_CREATE),
    (0, swagger_1.ApiOperation)({ summary: 'Create request or complaint', description: 'Creates a security, infrastructure, estate services, or support request.' }),
    (0, swagger_1.ApiBody)({ type: request_dto_1.CreateResidentRequestDto }),
    (0, swagger_1.ApiResponse)({ status: 201, description: 'Request 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", [request_dto_1.CreateResidentRequestDto, Object]),
    __metadata("design:returntype", void 0)
], RequestsController.prototype, "create", null);
__decorate([
    (0, common_1.Patch)(':id/respond'),
    (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.REQUESTS_RESPOND),
    (0, swagger_1.ApiOperation)({ summary: 'Respond to request', description: 'Adds a response and optionally updates status or assignment.' }),
    (0, swagger_1.ApiParam)({ name: 'id', example: 'request-uuid' }),
    (0, swagger_1.ApiBody)({ type: request_dto_1.RespondResidentRequestDto }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Request updated.' }),
    (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, request_dto_1.RespondResidentRequestDto, Object]),
    __metadata("design:returntype", void 0)
], RequestsController.prototype, "respond", null);
exports.RequestsController = RequestsController = __decorate([
    (0, swagger_1.ApiTags)('Resident Requests'),
    (0, swagger_docs_1.ApiProtectedEndpoint)(),
    (0, common_1.Controller)({ path: 'requests', version: '1' }),
    __metadata("design:paramtypes", [requests_service_1.RequestsService])
], RequestsController);
//# sourceMappingURL=requests.controller.js.map