"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.ReportsController = void 0;
const common_1 = require("@nestjs/common");
const reports_service_1 = require("./reports.service");
const report_filter_dto_1 = require("./dto/report-filter.dto");
const jwt_auth_guard_1 = require("../common/guard/jwt-auth.guard");
const tenant_guard_1 = require("../common/guard/tenant.guard");
let ReportsController = class ReportsController {
    constructor(reportsService) {
        this.reportsService = reportsService;
    }
    async getRevenue(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getRevenueReport(businessId, filters);
    }
    async getPackages(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getPackageSalesReport(businessId, filters);
    }
    async getRouters(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getRouterReport(businessId, filters);
    }
    async getLocations(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getLocationReport(businessId, filters);
    }
    async getCustomers(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getCustomerReport(businessId, filters);
    }
    async getDataUsage(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getDataUsageReport(businessId, filters);
    }
    async getPaymentSuccess(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getPaymentSuccessRateReport(businessId, filters);
    }
    async getTax(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getTaxReport(businessId, filters);
    }
    async getCommissions(filters, req) {
        const businessId = req.businessId || req.user?.businessId;
        return this.reportsService.getCommissionReport(businessId, filters);
    }
    async exportCsv(reportType, filters, req, res) {
        const businessId = req.businessId || req.user?.businessId;
        const csv = await this.reportsService.exportReportCsv(businessId, reportType, filters);
        res.setHeader('Content-Type', 'text/csv');
        res.setHeader('Content-Disposition', `attachment; filename="${reportType}-report.csv"`);
        res.send(csv);
    }
    async exportPdf(reportType, filters, req, res) {
        const businessId = req.businessId || req.user?.businessId;
        const pdfBuffer = await this.reportsService.exportReportPdf(businessId, reportType, filters);
        res.setHeader('Content-Type', 'application/pdf');
        res.setHeader('Content-Disposition', `attachment; filename="${reportType}-report.pdf"`);
        res.send(pdfBuffer);
    }
};
exports.ReportsController = ReportsController;
__decorate([
    (0, common_1.Get)('revenue'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getRevenue", null);
__decorate([
    (0, common_1.Get)('packages'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getPackages", null);
__decorate([
    (0, common_1.Get)('routers'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getRouters", null);
__decorate([
    (0, common_1.Get)('locations'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getLocations", null);
__decorate([
    (0, common_1.Get)('customers'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getCustomers", null);
__decorate([
    (0, common_1.Get)('data-usage'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getDataUsage", null);
__decorate([
    (0, common_1.Get)('payment-success'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getPaymentSuccess", null);
__decorate([
    (0, common_1.Get)('tax'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getTax", null);
__decorate([
    (0, common_1.Get)('commissions'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [report_filter_dto_1.ReportFilterDto, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "getCommissions", null);
__decorate([
    (0, common_1.Get)('export/csv/:reportType'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Param)('reportType')),
    __param(1, (0, common_1.Query)()),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, report_filter_dto_1.ReportFilterDto, Object, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "exportCsv", null);
__decorate([
    (0, common_1.Get)('export/pdf/:reportType'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Param)('reportType')),
    __param(1, (0, common_1.Query)()),
    __param(2, (0, common_1.Req)()),
    __param(3, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, report_filter_dto_1.ReportFilterDto, Object, Object]),
    __metadata("design:returntype", Promise)
], ReportsController.prototype, "exportPdf", null);
exports.ReportsController = ReportsController = __decorate([
    (0, common_1.Controller)('reports'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, tenant_guard_1.TenantGuard),
    __metadata("design:paramtypes", [reports_service_1.ReportsService])
], ReportsController);
