"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.OfflineController = 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 offline_dto_1 = require("./dto/offline.dto");
const offline_service_1 = require("./offline.service");
let OfflineController = class OfflineController {
    offlineService;
    constructor(offlineService) {
        this.offlineService = offlineService;
    }
    bootstrap(user, estateId) {
        return this.offlineService.bootstrap(user, estateId);
    }
    sync(dto, user) {
        return this.offlineService.sync(dto, user);
    }
};
exports.OfflineController = OfflineController;
__decorate([
    (0, common_1.Get)('bootstrap'),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.GUARD, client_1.UserRole.ESTATE_ADMIN, client_1.UserRole.SECURITY_SUPERVISOR),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.OFFLINE_BOOTSTRAP),
    (0, swagger_1.ApiOperation)({
        summary: 'Bootstrap offline gate data',
        description: 'Downloads active passes, active residents, and recent audit logs for offline-capable gate devices.'
    }),
    (0, swagger_1.ApiQuery)({ name: 'estateId', required: true, example: swagger_docs_1.ESTATE_ID_EXAMPLE, description: 'Estate to bootstrap.' }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Offline data returned.',
        schema: {
            example: {
                serverTime: '2026-05-16T12:00:00.000Z',
                activePasses: [{ id: swagger_docs_1.VISITOR_PASS_ID_EXAMPLE, estateId: swagger_docs_1.ESTATE_ID_EXAMPLE, status: 'ACTIVE' }],
                residents: [{ id: swagger_docs_1.RESIDENT_ID_EXAMPLE, name: 'Ade Okafor', unit: 'A12', phone: '+2348000000003' }],
                recentLogs: []
            }
        }
    }),
    __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)
], OfflineController.prototype, "bootstrap", null);
__decorate([
    (0, common_1.Post)('sync'),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.GUARD, client_1.UserRole.ESTATE_ADMIN, client_1.UserRole.SECURITY_SUPERVISOR),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.OFFLINE_SYNC),
    (0, swagger_1.ApiOperation)({
        summary: 'Submit offline event batch',
        description: 'Stores client offline event records idempotently by deviceId and clientEventId. Domain replay is not yet implemented.'
    }),
    (0, swagger_1.ApiBody)({ type: offline_dto_1.OfflineSyncDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Offline events accepted.',
        schema: {
            example: {
                accepted: 1,
                items: [
                    {
                        id: 'offline-sync-item-uuid',
                        estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                        deviceId: 'guard-device-001',
                        clientEventId: 'offline-event-001',
                        eventType: 'VISITOR_CHECKED_IN',
                        status: 'APPLIED'
                    }
                ]
            }
        }
    }),
    (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", [offline_dto_1.OfflineSyncDto, Object]),
    __metadata("design:returntype", void 0)
], OfflineController.prototype, "sync", null);
exports.OfflineController = OfflineController = __decorate([
    (0, swagger_1.ApiTags)('Offline'),
    (0, swagger_docs_1.ApiProtectedEndpoint)(),
    (0, common_1.Controller)({ path: 'offline', version: '1' }),
    __metadata("design:paramtypes", [offline_service_1.OfflineService])
], OfflineController);
//# sourceMappingURL=offline.controller.js.map