"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.EstatesController = 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_estate_dto_1 = require("./dto/create-estate.dto");
const estates_service_1 = require("./estates.service");
let EstatesController = class EstatesController {
    estatesService;
    constructor(estatesService) {
        this.estatesService = estatesService;
    }
    findAll(user) {
        return this.estatesService.findAll(user);
    }
    create(dto, user) {
        return this.estatesService.create(dto, user);
    }
};
exports.EstatesController = EstatesController;
__decorate([
    (0, common_1.Get)(),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.SUPER_ADMIN, client_1.UserRole.ESTATE_ADMIN),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.ESTATES_VIEW),
    (0, swagger_1.ApiOperation)({
        summary: 'List estates visible to the current user',
        description: 'SUPER_ADMIN and SALES_ADMIN receive all estates. ESTATE_ADMIN receives only their own estate.'
    }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Visible estates returned.',
        schema: {
            example: [
                {
                    id: swagger_docs_1.ESTATE_ID_EXAMPLE,
                    name: 'GreenPark Estate',
                    location: 'Lagos, Nigeria',
                    settings: { timezone: 'Africa/Lagos', gates: ['Main Gate'] },
                    branding: { primaryColor: '#0f766e' }
                }
            ]
        }
    }),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], EstatesController.prototype, "findAll", null);
__decorate([
    (0, common_1.Post)(),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.SUPER_ADMIN),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.ESTATES_MANAGE),
    (0, swagger_1.ApiOperation)({
        summary: 'Create an estate',
        description: 'Onboards a new estate. SUPER_ADMIN always can create estates; SALES_ADMIN can create estates when the ESTATES_MANAGE feature is enabled.'
    }),
    (0, swagger_1.ApiBody)({ type: create_estate_dto_1.CreateEstateDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Estate created.',
        schema: {
            example: {
                id: swagger_docs_1.ESTATE_ID_EXAMPLE,
                name: 'GreenPark Estate',
                location: 'Lagos, Nigeria',
                settings: { timezone: 'Africa/Lagos' },
                branding: { primaryColor: '#0f766e' }
            }
        }
    }),
    (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_estate_dto_1.CreateEstateDto, Object]),
    __metadata("design:returntype", void 0)
], EstatesController.prototype, "create", null);
exports.EstatesController = EstatesController = __decorate([
    (0, swagger_1.ApiTags)('Estates'),
    (0, swagger_docs_1.ApiProtectedEndpoint)(),
    (0, common_1.Controller)({ path: 'estates', version: '1' }),
    __metadata("design:paramtypes", [estates_service_1.EstatesService])
], EstatesController);
//# sourceMappingURL=estates.controller.js.map