"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 swagger_1 = require("@nestjs/swagger");
const prisma_service_1 = require("../prisma/prisma.service");
const envelope_1 = require("../../common/envelope");
const roles_decorator_1 = require("../../common/decorators/roles.decorator");
const roles_1 = require("../../common/roles");
const class_validator_1 = require("class-validator");
class CreateStaffDto {
}
__decorate([
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], CreateStaffDto.prototype, "fullName", void 0);
__decorate([
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], CreateStaffDto.prototype, "email", void 0);
__decorate([
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], CreateStaffDto.prototype, "phone", void 0);
__decorate([
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], CreateStaffDto.prototype, "password", void 0);
__decorate([
    (0, class_validator_1.IsOptional)(),
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], CreateStaffDto.prototype, "staffRole", void 0);
class SetGatewayDto {
}
__decorate([
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], SetGatewayDto.prototype, "defaultGateway", void 0);
class UpdateStudentPrivacyDto {
}
__decorate([
    (0, class_validator_1.IsOptional)(),
    (0, class_validator_1.IsBoolean)(),
    __metadata("design:type", Boolean)
], UpdateStudentPrivacyDto.prototype, "profileVisible", void 0);
let AdminController = class AdminController {
    constructor(prisma) {
        this.prisma = prisma;
    }
    async dashboard() {
        const users = await this.prisma.user.count();
        const courses = await this.prisma.course.count();
        const enrollments = await this.prisma.enrollment.count();
        const payments = await this.prisma.payment.count();
        return (0, envelope_1.ok)({ users, courses, enrollments, payments });
    }
    async students(q) {
        const where = {};
        if (q)
            where.OR = [{ fullName: { contains: q, mode: 'insensitive' } }, { matricNumber: { contains: q, mode: 'insensitive' } }, { email: { contains: q, mode: 'insensitive' } }];
        const items = await this.prisma.user.findMany({ where, orderBy: { createdAt: 'desc' }, select: { id: true, fullName: true, email: true, phone: true, role: true, matricNumber: true, profileVisible: true } });
        return (0, envelope_1.ok)(items);
    }
    async studentPrivacy(studentId, dto) {
        const u = await this.prisma.user.update({ where: { id: studentId }, data: dto });
        return (0, envelope_1.ok)(u);
    }
    async staff() {
        const items = await this.prisma.staffProfile.findMany({ include: { user: { select: { id: true, fullName: true, email: true, phone: true, role: true } } } });
        return (0, envelope_1.ok)(items);
    }
    async setGateway(dto) {
        await this.prisma.activityLog.create({ data: { action: 'SET_DEFAULT_PAYMENT_GATEWAY', details: { gateway: dto.defaultGateway } } });
        return (0, envelope_1.ok)({ defaultGateway: dto.defaultGateway });
    }
};
exports.AdminController = AdminController;
__decorate([
    (0, common_1.Get)('dashboard'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "dashboard", null);
__decorate([
    (0, common_1.Get)('students'),
    __param(0, (0, common_1.Query)('q')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "students", null);
__decorate([
    (0, common_1.Patch)('students/:studentId/privacy'),
    __param(0, (0, common_1.Param)('studentId')),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, UpdateStudentPrivacyDto]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "studentPrivacy", null);
__decorate([
    (0, common_1.Get)('staff'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "staff", null);
__decorate([
    (0, common_1.Post)('settings/payment-gateway'),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [SetGatewayDto]),
    __metadata("design:returntype", Promise)
], AdminController.prototype, "setGateway", null);
exports.AdminController = AdminController = __decorate([
    (0, swagger_1.ApiTags)('Admin'),
    (0, swagger_1.ApiBearerAuth)(),
    (0, roles_decorator_1.Roles)(roles_1.UserRole.ADMIN),
    (0, common_1.Controller)('admin'),
    __metadata("design:paramtypes", [prisma_service_1.PrismaService])
], AdminController);
//# sourceMappingURL=admin.controller.js.map