"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.AdminController = void 0;
const common_1 = require("@nestjs/common");
const admin_service_1 = require("./admin.service");
const admin_dto_1 = require("./dto/admin.dto");
const jwt_auth_guard_1 = require("../common/guard/jwt-auth.guard");
const roles_guard_1 = require("../common/guard/roles.guard");
const roles_decorator_1 = require("../common/decorators/roles.decorator");
let AdminController = class AdminController {
    constructor(adminService) {
        this.adminService = adminService;
    }
    async getAllBusinesses(status, search, page, limit) {
        return this.adminService.getAllBusinesses({
            status,
            search,
            page: page ? Number(page) : undefined,
            limit: limit ? Number(limit) : undefined,
        });
    }
    async createBusiness(dto) {
        return this.adminService.createBusiness(dto);
    }
    async getBusinessDetail(id) {
        return this.adminService.getBusinessDetail(id);
    }
    async suspendBusiness(id, reason) {
        if (!reason)
            throw new Error('Suspension reason is required');
        return this.adminService.suspendBusiness(id, reason);
    }
    async unsuspendBusiness(id) {
        return this.adminService.unsuspendBusiness(id);
    }
    async deleteBusiness(id) {
        return this.adminService.deleteBusiness(id);
    }
    async impersonateBusiness(id, req) {
        const adminId = req.user?.id;
        if (!adminId)
            throw new Error('User ID is required');
        return this.adminService.impersonateBusiness(id, adminId);
    }
    async getPlatformOverview() {
        return this.adminService.getPlatformOverview();
    }
    async getPlatformRevenue(startDate, endDate) {
        return this.adminService.getPlatformRevenue(startDate, endDate);
    }
    async getCommissions(filters) {
        return this.adminService.getCommissions(filters);
    }
    async updateCommission(id, dto) {
        return this.adminService.updateCommission(id, dto);
    }
    async getSystemLogs(filters) {
        return this.adminService.getSystemLogs(filters);
    }
    async getAuditLogs(filters) {
        return this.adminService.getAuditLogs(filters);
    }
    async getFailedJobs() {
        return this.adminService.getFailedJobs();
    }
    async retryFailedJob(id) {
        return this.adminService.retryFailedJob(id);
    }
    async cleanFailedJobs() {
        return this.adminService.cleanFailedJobs();
    }
    async getSystemSettings() {
        return this.adminService.getSystemSettings();
    }
    async updateSystemSetting(key, value, description, isEncrypted) {
        if (!value)
            throw new Error('Value is required');
        return this.adminService.updateSystemSetting(key, value, description, isEncrypted);
    }
    async backupDatabase() {
        return this.adminService.backupDatabase();
    }
    async getSystemHealth() {
        return this.adminService.getSystemHealth();
    }
};
exports.AdminController = AdminController;
__decorate([
    (0, common_1.Get)('businesses'),
    __param(0, (0, common_1.Query)('status')),
    __param(1, (0, common_1.Query)('search')),
    __param(2, (0, common_1.Query)('page')),
    __param(3, (0, common_1.Query)('limit')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Number, Number]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getAllBusinesses", null);
__decorate([
    (0, common_1.Post)('businesses'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [admin_dto_1.CreateBusinessDto]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "createBusiness", null);
__decorate([
    (0, common_1.Get)('businesses/:id'),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getBusinessDetail", null);
__decorate([
    (0, common_1.Post)('businesses/:id/suspend'),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Body)('reason')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "suspendBusiness", null);
__decorate([
    (0, common_1.Post)('businesses/:id/unsuspend'),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "unsuspendBusiness", null);
__decorate([
    (0, common_1.Delete)('businesses/:id'),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "deleteBusiness", null);
__decorate([
    (0, common_1.Post)('businesses/:id/impersonate'),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "impersonateBusiness", null);
__decorate([
    (0, common_1.Get)('overview'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getPlatformOverview", null);
__decorate([
    (0, common_1.Get)('revenue'),
    __param(0, (0, common_1.Query)('startDate')),
    __param(1, (0, common_1.Query)('endDate')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getPlatformRevenue", null);
__decorate([
    (0, common_1.Get)('commissions'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [admin_dto_1.CommissionFilter]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getCommissions", null);
__decorate([
    (0, common_1.Patch)('commissions/:id'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, admin_dto_1.UpdateCommissionDto]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "updateCommission", null);
__decorate([
    (0, common_1.Get)('logs'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [admin_dto_1.LogFilterDto]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getSystemLogs", null);
__decorate([
    (0, common_1.Get)('audit-logs'),
    (0, common_1.UsePipes)(new common_1.ValidationPipe({ transform: true })),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [admin_dto_1.AuditFilterDto]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getAuditLogs", null);
__decorate([
    (0, common_1.Get)('jobs/failed'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getFailedJobs", null);
__decorate([
    (0, common_1.Post)('jobs/:id/retry'),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "retryFailedJob", null);
__decorate([
    (0, common_1.Delete)('jobs/clean'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "cleanFailedJobs", null);
__decorate([
    (0, common_1.Get)('settings'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getSystemSettings", null);
__decorate([
    (0, common_1.Put)('settings/:key'),
    __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)
], AdminController.prototype, "updateSystemSetting", null);
__decorate([
    (0, common_1.Post)('backup'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "backupDatabase", null);
__decorate([
    (0, common_1.Get)('health'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "getSystemHealth", null);
exports.AdminController = AdminController = __decorate([
    (0, common_1.Controller)('admin'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, roles_guard_1.RolesGuard),
    (0, roles_decorator_1.Roles)('super_admin'),
    __metadata("design:paramtypes", [admin_service_1.AdminService])
], AdminController);
