"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.SettingsController = void 0;
const common_1 = require("@nestjs/common");
const settings_service_1 = require("./settings.service");
const jwt_auth_guard_1 = require("../common/guard/jwt-auth.guard");
const tenant_guard_1 = require("../common/guard/tenant.guard");
const roles_guard_1 = require("../common/guard/roles.guard");
const roles_decorator_1 = require("../common/decorators/roles.decorator");
let SettingsController = class SettingsController {
    constructor(settingsService) {
        this.settingsService = settingsService;
    }
    async getSystemSettings() {
        return this.settingsService.getAllSystemSettings(true);
    }
    async updateSystemSetting(key, value, description, isEncrypted) {
        if (!value)
            throw new Error('Value is required');
        return this.settingsService.setSystemSetting(key, value, description, isEncrypted);
    }
    async getBusinessSettings(req) {
        const businessId = req.businessId || req.user?.businessId;
        if (!businessId)
            throw new Error('Business ID is required');
        return this.settingsService.getAllBusinessSettings(businessId);
    }
    async updateBusinessSetting(key, value, req, description, isEncrypted) {
        const businessId = req.businessId || req.user?.businessId;
        if (!businessId)
            throw new Error('Business ID is required');
        if (!value)
            throw new Error('Value is required');
        return this.settingsService.setBusinessSetting(businessId, key, value, description, isEncrypted);
    }
    async getMpesaConfig(req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.settingsService.getMpesaConfiguration(businessId);
    }
    async getEmailConfig() {
        return this.settingsService.getEmailConfiguration();
    }
    async getSmsConfig() {
        return this.settingsService.getSmsConfiguration();
    }
};
exports.SettingsController = SettingsController;
__decorate([
    (0, common_1.Get)('system'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, roles_guard_1.RolesGuard),
    (0, roles_decorator_1.Roles)('super_admin'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "getSystemSettings", null);
__decorate([
    (0, common_1.Put)('system/:key'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, roles_guard_1.RolesGuard),
    (0, roles_decorator_1.Roles)('super_admin'),
    __param(0, (0, common_1.Param)('key')),
    __param(1, (0, common_1.Body)('value')),
    __param(2, (0, common_1.Body)('description')),
    __param(3, (0, common_1.Body)('isEncrypted')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, String, Boolean]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "updateSystemSetting", null);
__decorate([
    (0, common_1.Get)('business'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, tenant_guard_1.TenantGuard),
    __param(0, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "getBusinessSettings", null);
__decorate([
    (0, common_1.Put)('business/:key'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, tenant_guard_1.TenantGuard, roles_guard_1.RolesGuard),
    (0, roles_decorator_1.Roles)('business_owner'),
    __param(0, (0, common_1.Param)('key')),
    __param(1, (0, common_1.Body)('value')),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Body)('description')),
    __param(4, (0, common_1.Body)('isEncrypted')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object, String, Boolean]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "updateBusinessSetting", null);
__decorate([
    (0, common_1.Get)('mpesa'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, tenant_guard_1.TenantGuard),
    __param(0, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "getMpesaConfig", null);
__decorate([
    (0, common_1.Get)('email'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, roles_guard_1.RolesGuard),
    (0, roles_decorator_1.Roles)('super_admin'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "getEmailConfig", null);
__decorate([
    (0, common_1.Get)('sms'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, roles_guard_1.RolesGuard),
    (0, roles_decorator_1.Roles)('super_admin'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "getSmsConfig", null);
exports.SettingsController = SettingsController = __decorate([
    (0, common_1.Controller)('settings'),
    __metadata("design:paramtypes", [settings_service_1.SettingsService])
], SettingsController);
