"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 api_1 = require("@hed-hog/api");
const api_locale_1 = require("@hed-hog/api-locale");
const api_pagination_1 = require("@hed-hog/api-pagination");
const common_1 = require("@nestjs/common");
const platform_express_1 = require("@nestjs/platform-express");
const confirm_import_dto_1 = require("./dto/confirm-import.dto");
const create_dto_1 = require("./dto/create.dto");
const delete_dto_1 = require("./dto/delete.dto");
const export_dto_1 = require("./dto/export.dto");
const setting_user_dto_1 = require("./dto/setting-user.dto");
const setting_dto_1 = require("./dto/setting.dto");
const update_setting_list_dto_1 = require("./dto/update-setting-list.dto");
const update_dto_1 = require("./dto/update.dto");
const setting_service_1 = require("./setting.service");
let SettingsController = class SettingsController {
    constructor(settingService) {
        this.settingService = settingService;
    }
    async exportSettings({ secrets = false }, res) {
        const compressedData = await this.settingService.exportSettings(secrets);
        res.send(compressedData);
    }
    async initialSettings() {
        return this.settingService.getSystemSettings();
    }
    async getSettingFromGroup(paginationParams, locale, slug, { id: userId }) {
        return this.settingService.getSettingFromGroup(locale, paginationParams, slug, userId);
    }
    async listSettingGroups(paginationParams, locale) {
        return this.settingService.listSettingGroups(locale, paginationParams);
    }
    async getUserSettings({ id }) {
        return this.settingService.getUserSettings(id);
    }
    async getEffectiveSettings({ id }) {
        return this.settingService.getEffectiveSettings(id);
    }
    async listSettings(paginationParams, locale) {
        return this.settingService.listSettings(locale, paginationParams);
    }
    async get(settingId) {
        return this.settingService.get(settingId);
    }
    async importSettings(locale, file) {
        return this.settingService.importSettings(locale, file);
    }
    async confirmImport(data) {
        return this.settingService.confirmImport(data.settings);
    }
    async create(locale, data) {
        return this.settingService.create(data, locale);
    }
    async updateUserFromSlug(slug, { value }, { id }, locale) {
        return this.settingService.setSettingUserValue(locale, id, slug, value);
    }
    async updateFromSlug(slug, data) {
        return this.settingService.updateFromSlug(slug, data);
    }
    async updateSettingListOptions(settingId, data) {
        return this.settingService.updateSettingListOptions(settingId, data);
    }
    async setManySettings(data) {
        return this.settingService.setManySettings(data);
    }
    async update(settingId, data) {
        return this.settingService.update({
            id: settingId,
            data,
        });
    }
    async delete(locale, data) {
        return this.settingService.delete(locale, data);
    }
};
exports.SettingsController = SettingsController;
__decorate([
    (0, common_1.Get)('export'),
    (0, common_1.Header)('Content-Type', 'application/octet-stream'),
    (0, common_1.Header)('Content-Disposition', 'attachment; filename="settings.hedhog"'),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [export_dto_1.ExportDto, Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "exportSettings", null);
__decorate([
    (0, api_1.Public)(),
    (0, common_1.Get)('initial'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "initialSettings", null);
__decorate([
    (0, common_1.Get)('group/:slug'),
    __param(0, (0, api_pagination_1.Pagination)()),
    __param(1, (0, api_locale_1.Locale)()),
    __param(2, (0, common_1.Param)('slug')),
    __param(3, (0, api_1.User)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object, String, Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "getSettingFromGroup", null);
__decorate([
    (0, api_1.Public)(),
    (0, common_1.Get)('group'),
    __param(0, (0, api_pagination_1.Pagination)()),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "listSettingGroups", null);
__decorate([
    (0, common_1.Get)('/user'),
    __param(0, (0, api_1.User)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "getUserSettings", null);
__decorate([
    (0, common_1.Get)('/effective'),
    __param(0, (0, api_1.User)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "getEffectiveSettings", null);
__decorate([
    (0, common_1.Get)(),
    __param(0, (0, api_pagination_1.Pagination)()),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "listSettings", null);
__decorate([
    (0, common_1.Get)(':settingId'),
    __param(0, (0, common_1.Param)('settingId', common_1.ParseIntPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "get", null);
__decorate([
    (0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file')),
    (0, common_1.Post)('import'),
    __param(0, (0, api_locale_1.Locale)()),
    __param(1, (0, common_1.UploadedFile)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "importSettings", null);
__decorate([
    (0, common_1.Post)('import/confirm'),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [confirm_import_dto_1.ConfirmImportDTO]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "confirmImport", null);
__decorate([
    (0, common_1.Post)(),
    __param(0, (0, api_locale_1.Locale)()),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, create_dto_1.CreateDTO]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "create", null);
__decorate([
    (0, common_1.Put)('user/:slug'),
    __param(0, (0, common_1.Param)('slug')),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_1.User)()),
    __param(3, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, setting_user_dto_1.SettingUserDTO, Object, Object]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "updateUserFromSlug", null);
__decorate([
    (0, common_1.Put)(':slug'),
    __param(0, (0, common_1.Param)('slug')),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, update_dto_1.UpdateDTO]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "updateFromSlug", null);
__decorate([
    (0, common_1.Put)(':settingId/options'),
    __param(0, (0, common_1.Param)('settingId', common_1.ParseIntPipe)),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, update_setting_list_dto_1.UpdateSettingListDTO]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "updateSettingListOptions", null);
__decorate([
    (0, common_1.Put)(),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [setting_dto_1.SettingDTO]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "setManySettings", null);
__decorate([
    (0, common_1.Patch)(':settingId'),
    __param(0, (0, common_1.Param)('settingId', common_1.ParseIntPipe)),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, update_dto_1.UpdateDTO]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "update", null);
__decorate([
    (0, common_1.Delete)(),
    __param(0, (0, api_locale_1.Locale)()),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, delete_dto_1.DeleteDTO]),
    __metadata("design:returntype", Promise)
], SettingsController.prototype, "delete", null);
exports.SettingsController = SettingsController = __decorate([
    (0, api_1.Role)(),
    (0, common_1.Controller)('setting'),
    __param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => setting_service_1.SettingService))),
    __metadata("design:paramtypes", [setting_service_1.SettingService])
], SettingsController);
//# sourceMappingURL=setting.controller.js.map