"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.ResidentsController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const client_1 = require("@prisma/client");
const current_user_decorator_1 = require("../common/current-user.decorator");
const require_role_decorator_1 = require("../auth/require-role.decorator");
const feature_catalog_1 = require("../features/feature-catalog");
const require_feature_decorator_1 = require("../features/require-feature.decorator");
const swagger_docs_1 = require("../common/swagger-docs");
const create_resident_dto_1 = require("./dto/create-resident.dto");
const residents_service_1 = require("./residents.service");
let ResidentsController = class ResidentsController {
    residentsService;
    constructor(residentsService) {
        this.residentsService = residentsService;
    }
    findAll(user, estateId, q) {
        return this.residentsService.findAll(user, estateId, q);
    }
    create(dto, user) {
        return this.residentsService.create(dto, user);
    }
};
exports.ResidentsController = ResidentsController;
__decorate([
    (0, common_1.Get)(),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.ESTATE_ADMIN, client_1.UserRole.SECURITY_SUPERVISOR, client_1.UserRole.RESIDENT),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.RESIDENTS_VIEW),
    (0, swagger_1.ApiOperation)({
        summary: 'List or search residents',
        description: 'Returns residents for the resolved estate scope. Use q to search name, unit, or phone.'
    }),
    (0, swagger_1.ApiQuery)({ name: 'estateId', required: false, example: swagger_docs_1.ESTATE_ID_EXAMPLE, description: 'Estate scope. Required for SUPER_ADMIN.' }),
    (0, swagger_1.ApiQuery)({ name: 'q', required: false, example: 'Ada', description: 'Optional search text.' }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Residents returned.',
        schema: {
            example: [
                {
                    id: swagger_docs_1.RESIDENT_ID_EXAMPLE,
                    estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                    userId: swagger_docs_1.USER_ID_EXAMPLE,
                    unit: 'A12',
                    phone: '+2348000000003',
                    name: 'Ade Okafor',
                    status: 'ACTIVE'
                }
            ]
        }
    }),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __param(1, (0, common_1.Query)('estateId')),
    __param(2, (0, common_1.Query)('q')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, String]),
    __metadata("design:returntype", void 0)
], ResidentsController.prototype, "findAll", null);
__decorate([
    (0, common_1.Post)(),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.ESTATE_ADMIN, client_1.UserRole.SECURITY_SUPERVISOR),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.RESIDENTS_MANAGE),
    (0, swagger_1.ApiOperation)({
        summary: 'Create resident',
        description: 'Creates both a RESIDENT user account and its resident profile in the estate.'
    }),
    (0, swagger_1.ApiBody)({ type: create_resident_dto_1.CreateResidentDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Resident profile created.',
        schema: {
            example: {
                id: swagger_docs_1.RESIDENT_ID_EXAMPLE,
                estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                userId: swagger_docs_1.USER_ID_EXAMPLE,
                name: 'Ade Okafor',
                phone: '+2348000000300',
                unit: 'A12',
                status: 'ACTIVE'
            }
        }
    }),
    (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", [create_resident_dto_1.CreateResidentDto, Object]),
    __metadata("design:returntype", void 0)
], ResidentsController.prototype, "create", null);
exports.ResidentsController = ResidentsController = __decorate([
    (0, swagger_1.ApiTags)('Residents'),
    (0, swagger_docs_1.ApiProtectedEndpoint)(),
    (0, common_1.Controller)({ path: 'residents', version: '1' }),
    __metadata("design:paramtypes", [residents_service_1.ResidentsService])
], ResidentsController);
//# sourceMappingURL=residents.controller.js.map