"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.CheckinController = 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 checkin_service_1 = require("./checkin.service");
const checkin_dto_1 = require("./dto/checkin.dto");
let CheckinController = class CheckinController {
    checkinService;
    constructor(checkinService) {
        this.checkinService = checkinService;
    }
    scan(dto, user) {
        return this.checkinService.checkinByQr(dto, user);
    }
    manual(dto, user) {
        return this.checkinService.checkinByCode(dto, user);
    }
    checkout(dto, user) {
        return this.checkinService.checkout(dto, user);
    }
};
exports.CheckinController = CheckinController;
__decorate([
    (0, common_1.Post)('scan'),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.GUARD),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.CHECKIN_SCAN),
    (0, swagger_1.ApiOperation)({
        summary: 'Check in visitor by QR token',
        description: 'Validates guard identity, estate scope, pass status, validity window, and remaining entries before creating a visit session.'
    }),
    (0, swagger_1.ApiBody)({ type: checkin_dto_1.ScanCheckinDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Visitor checked in.',
        schema: {
            example: {
                id: swagger_docs_1.VISIT_SESSION_ID_EXAMPLE,
                estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                visitorPassId: swagger_docs_1.VISITOR_PASS_ID_EXAMPLE,
                guardId: swagger_docs_1.GUARD_ID_EXAMPLE,
                deviceId: 'gate-tablet-001',
                entryGate: 'Main Gate',
                status: 'CHECKED_IN',
                checkinTime: '2026-05-16T12:00:00.000Z'
            }
        }
    }),
    (0, swagger_1.ApiBadRequestResponse)({
        description: 'Pass is inactive, expired, outside validity window, exhausted, or guard identity does not match.',
        schema: { example: { statusCode: 400, message: 'Visitor pass has no remaining entries', error: 'Bad Request' } }
    }),
    (0, swagger_docs_1.ApiNotFoundError)('Visitor pass or active guard'),
    (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", [checkin_dto_1.ScanCheckinDto, Object]),
    __metadata("design:returntype", void 0)
], CheckinController.prototype, "scan", null);
__decorate([
    (0, common_1.Post)('manual'),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.GUARD),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.CHECKIN_MANUAL),
    (0, swagger_1.ApiOperation)({
        summary: 'Check in visitor by manual code',
        description: 'Uses the manual visitor code instead of QR token, then applies the same guard, estate, status, time-window, and entry-count validation.'
    }),
    (0, swagger_1.ApiBody)({ type: checkin_dto_1.ManualCheckinDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Visitor checked in.',
        schema: {
            example: {
                id: swagger_docs_1.VISIT_SESSION_ID_EXAMPLE,
                estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                visitorPassId: swagger_docs_1.VISITOR_PASS_ID_EXAMPLE,
                guardId: swagger_docs_1.GUARD_ID_EXAMPLE,
                deviceId: 'gate-tablet-001',
                entryGate: 'Main Gate',
                status: 'CHECKED_IN'
            }
        }
    }),
    (0, swagger_1.ApiBadRequestResponse)({
        description: 'Pass is inactive, expired, outside validity window, exhausted, or guard identity does not match.',
        schema: { example: { statusCode: 400, message: 'Visitor pass is outside its validity window', error: 'Bad Request' } }
    }),
    (0, swagger_docs_1.ApiNotFoundError)('Visitor pass or active guard'),
    (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", [checkin_dto_1.ManualCheckinDto, Object]),
    __metadata("design:returntype", void 0)
], CheckinController.prototype, "manual", null);
__decorate([
    (0, common_1.Post)('checkout'),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.GUARD),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.CHECKOUT),
    (0, swagger_1.ApiOperation)({
        summary: 'Check out visitor',
        description: 'Closes an open visit session and records exit gate, checkout time, and checkout audit log.'
    }),
    (0, swagger_1.ApiBody)({ type: checkin_dto_1.CheckoutDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Visitor checked out.',
        schema: {
            example: {
                id: swagger_docs_1.VISIT_SESSION_ID_EXAMPLE,
                estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                visitorPassId: swagger_docs_1.VISITOR_PASS_ID_EXAMPLE,
                guardId: swagger_docs_1.GUARD_ID_EXAMPLE,
                deviceId: 'gate-tablet-001',
                exitGate: 'Main Gate',
                status: 'CHECKED_OUT',
                checkoutTime: '2026-05-16T13:00:00.000Z'
            }
        }
    }),
    (0, swagger_1.ApiBadRequestResponse)({
        description: 'Visit session is already checked out or guard identity does not match.',
        schema: { example: { statusCode: 400, message: 'Visit session is already checked out', error: 'Bad Request' } }
    }),
    (0, swagger_docs_1.ApiNotFoundError)('Visit session or active guard'),
    (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", [checkin_dto_1.CheckoutDto, Object]),
    __metadata("design:returntype", void 0)
], CheckinController.prototype, "checkout", null);
exports.CheckinController = CheckinController = __decorate([
    (0, swagger_1.ApiTags)('Checkin'),
    (0, swagger_docs_1.ApiProtectedEndpoint)(),
    (0, common_1.Controller)({ path: 'checkin', version: '1' }),
    __metadata("design:paramtypes", [checkin_service_1.CheckinService])
], CheckinController);
//# sourceMappingURL=checkin.controller.js.map