"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.IntegrityAdminController = void 0;
const openapi = require("@nestjs/swagger");
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const decorators_1 = require("../decorators");
const integrity_dto_1 = require("../dtos/integrity.dto");
const enum_1 = require("../enum");
const auth_guard_1 = require("../middleware/auth.guard");
const logging_repository_1 = require("../repositories/logging.repository");
const integrity_service_1 = require("../services/integrity.service");
const file_1 = require("../utils/file");
const validation_1 = require("../validation");
let IntegrityAdminController = class IntegrityAdminController {
    logger;
    service;
    constructor(logger, service) {
        this.logger = logger;
        this.service = service;
    }
    getIntegrityReportSummary() {
        return this.service.getIntegrityReportSummary();
    }
    getIntegrityReport(dto) {
        return this.service.getIntegrityReport(dto);
    }
    async getIntegrityReportFile({ id }, res, next) {
        await (0, file_1.sendFile)(res, next, () => this.service.getIntegrityReportFile(id), this.logger);
    }
    async deleteIntegrityReport(auth, { id }) {
        await this.service.deleteIntegrityReport(auth.user.id, id);
    }
    getIntegrityReportCsv({ type }, res) {
        res.setHeader('Content-Type', 'text/csv');
        res.setHeader('Cache-Control', 'private, no-cache, no-transform');
        res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(`${Date.now()}-${type}.csv`)}"`);
        this.service.getIntegrityReportCsv(type).pipe(res);
    }
};
exports.IntegrityAdminController = IntegrityAdminController;
__decorate([
    (0, common_1.Get)('summary'),
    (0, decorators_1.Endpoint)({
        summary: 'Get integrity report summary',
        description: 'Get a count of the items flagged in each integrity report',
        history: new decorators_1.HistoryBuilder().added('v3.0.0').alpha('v3.0.0'),
    }),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.Maintenance, admin: true }),
    openapi.ApiResponse({ status: 200, type: require("../dtos/integrity.dto").IntegrityReportSummaryResponseDto }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], IntegrityAdminController.prototype, "getIntegrityReportSummary", null);
__decorate([
    (0, common_1.Get)('report'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, decorators_1.Endpoint)({
        summary: 'Get integrity report by type',
        description: 'Get all flagged items by integrity report type',
        history: new decorators_1.HistoryBuilder().added('v3.0.0').alpha('v3.0.0'),
    }),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.Maintenance, admin: true }),
    openapi.ApiResponse({ status: common_1.HttpStatus.OK, type: require("../dtos/integrity.dto").IntegrityReportResponseDto }),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [integrity_dto_1.IntegrityGetReportDto]),
    __metadata("design:returntype", Promise)
], IntegrityAdminController.prototype, "getIntegrityReport", null);
__decorate([
    (0, common_1.Get)('report/:id/file'),
    (0, decorators_1.Endpoint)({
        summary: 'Download flagged file',
        description: 'Download the untracked/broken file if one exists',
        history: new decorators_1.HistoryBuilder().added('v3.0.0').alpha('v3.0.0'),
    }),
    (0, auth_guard_1.FileResponse)(),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.Maintenance, admin: true }),
    openapi.ApiResponse({ status: 200 }),
    __param(0, (0, common_1.Param)()),
    __param(1, (0, common_1.Res)()),
    __param(2, (0, common_1.Next)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [validation_1.UUIDv7ParamDto, Object, Function]),
    __metadata("design:returntype", Promise)
], IntegrityAdminController.prototype, "getIntegrityReportFile", null);
__decorate([
    (0, common_1.Delete)('report/:id'),
    (0, decorators_1.Endpoint)({
        summary: 'Delete integrity report item',
        description: 'Delete a given report item and perform corresponding deletion (e.g. trash asset, delete file)',
        history: new decorators_1.HistoryBuilder().added('v3.0.0').alpha('v3.0.0'),
    }),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.Maintenance, admin: true }),
    openapi.ApiResponse({ status: 200 }),
    __param(0, (0, auth_guard_1.Auth)()),
    __param(1, (0, common_1.Param)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, validation_1.UUIDv7ParamDto]),
    __metadata("design:returntype", Promise)
], IntegrityAdminController.prototype, "deleteIntegrityReport", null);
__decorate([
    (0, common_1.Get)('report/:type/csv'),
    (0, decorators_1.Endpoint)({
        summary: 'Export integrity report by type as CSV',
        description: 'Get all integrity report entries for a given type as a CSV',
        history: new decorators_1.HistoryBuilder().added('v3.0.0').alpha('v3.0.0'),
    }),
    (0, auth_guard_1.FileResponse)(),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.Maintenance, admin: true }),
    openapi.ApiResponse({ status: 200 }),
    __param(0, (0, common_1.Param)()),
    __param(1, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [integrity_dto_1.IntegrityReportTypeParamDto, Object]),
    __metadata("design:returntype", void 0)
], IntegrityAdminController.prototype, "getIntegrityReportCsv", null);
exports.IntegrityAdminController = IntegrityAdminController = __decorate([
    (0, swagger_1.ApiTags)(enum_1.ApiTag.Maintenance),
    (0, common_1.Controller)('admin/integrity'),
    __metadata("design:paramtypes", [logging_repository_1.LoggingRepository,
        integrity_service_1.IntegrityService])
], IntegrityAdminController);
//# sourceMappingURL=integrity-admin.controller.js.map