"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.ProfileController = 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 profile_dto_1 = require("./dto/profile.dto");
const profile_service_1 = require("./profile.service");
let ProfileController = class ProfileController {
    profileService;
    constructor(profileService) {
        this.profileService = profileService;
    }
    getMe(user) {
        return this.profileService.getMe(user);
    }
    getDemoAccess(user) {
        return this.profileService.getDemoAccess(user);
    }
    updateMe(user, dto) {
        return this.profileService.updateMe(user, dto);
    }
};
exports.ProfileController = ProfileController;
__decorate([
    (0, common_1.Get)('me'),
    (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.PROFILE_VIEW),
    (0, swagger_1.ApiOperation)({
        summary: 'View current profile',
        description: 'Returns the signed-in user profile, resident or guard role profile, profile completion checklist, and resident-safe estate plan comparison.'
    }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Profile returned.',
        schema: {
            example: {
                completion: { completion: 86, complete: false, missing: ['Profile confirmation'] },
                currentPlan: { code: 'STARTER', name: 'GateWise Starter', features: ['VISITOR_PASSES_CREATE'] },
                planComparison: { showPricing: false, upgrades: [{ code: 'SECURE', name: 'GateWise Secure' }] }
            }
        }
    }),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "getMe", null);
__decorate([
    (0, common_1.Get)('demo-access'),
    (0, require_role_decorator_1.RequireRole)(client_1.UserRole.ESTATE_ADMIN),
    (0, require_feature_decorator_1.RequireFeature)(feature_catalog_1.FeatureKey.PROFILE_VIEW),
    (0, swagger_1.ApiOperation)({
        summary: 'Verify protected demo access',
        description: 'Confirms the signed-in estate admin has an approved, active, time-limited demo session before the WebApp opens the demo workspace.'
    }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Demo access decision returned.',
        schema: {
            example: {
                approved: true,
                roleRequired: 'ESTATE_ADMIN',
                estate: { id: 'estate-uuid', name: 'Crown View Estate' },
                expiresAt: '2026-05-24T18:00:00.000Z',
                maxSessionMinutes: 120
            }
        }
    }),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "getDemoAccess", null);
__decorate([
    (0, common_1.Patch)('me'),
    (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.PROFILE_MANAGE),
    (0, swagger_1.ApiOperation)({
        summary: 'Update current profile',
        description: 'Updates names, address, email, block/flat data, profile image URLs, emergency contact, household members, and confirmation status. Image payloads store processing metadata for resized/compressed assets.'
    }),
    (0, swagger_1.ApiBody)({ type: profile_dto_1.UpdateMyProfileDto }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Profile updated with recalculated completion.',
        schema: { example: { completion: { completion: 100, complete: true, missing: [] } } }
    }),
    (0, swagger_docs_1.ApiValidationError)(),
    __param(0, (0, current_user_decorator_1.CurrentUser)()),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, profile_dto_1.UpdateMyProfileDto]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "updateMe", null);
exports.ProfileController = ProfileController = __decorate([
    (0, swagger_1.ApiTags)('Profile'),
    (0, swagger_docs_1.ApiProtectedEndpoint)(),
    (0, common_1.Controller)({ path: 'profile', version: '1' }),
    __metadata("design:paramtypes", [profile_service_1.ProfileService])
], ProfileController);
//# sourceMappingURL=profile.controller.js.map