"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.AdminSupportController = exports.SupportController = 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 CreateTicketDto {
}
__decorate([
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], CreateTicketDto.prototype, "subject", void 0);
__decorate([
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], CreateTicketDto.prototype, "message", void 0);
__decorate([
    (0, class_validator_1.IsOptional)(),
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], CreateTicketDto.prototype, "priority", void 0);
class UpdateTicketDto {
}
__decorate([
    (0, class_validator_1.IsOptional)(),
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], UpdateTicketDto.prototype, "status", void 0);
__decorate([
    (0, class_validator_1.IsOptional)(),
    (0, class_validator_1.IsString)(),
    __metadata("design:type", String)
], UpdateTicketDto.prototype, "adminNote", void 0);
let SupportController = class SupportController {
    constructor(prisma) {
        this.prisma = prisma;
    }
    async create(req, dto) {
        const userId = req.user.userId;
        const t = await this.prisma.supportTicket.create({ data: { userId, subject: dto.subject, message: dto.message, priority: dto.priority ?? 'medium' } });
        return (0, envelope_1.ok)(t);
    }
    async my(req) {
        const userId = req.user.userId;
        const items = await this.prisma.supportTicket.findMany({ where: { userId }, orderBy: { createdAt: 'desc' } });
        return (0, envelope_1.ok)(items);
    }
};
exports.SupportController = SupportController;
__decorate([
    (0, common_1.Post)('support/tickets'),
    __param(0, (0, common_1.Req)()),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, CreateTicketDto]),
    __metadata("design:returntype", Promise)
], SupportController.prototype, "create", null);
__decorate([
    (0, common_1.Get)('support/tickets/my'),
    __param(0, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], SupportController.prototype, "my", null);
exports.SupportController = SupportController = __decorate([
    (0, swagger_1.ApiTags)('Support'),
    (0, swagger_1.ApiBearerAuth)(),
    (0, common_1.Controller)(),
    __metadata("design:paramtypes", [prisma_service_1.PrismaService])
], SupportController);
let AdminSupportController = class AdminSupportController {
    constructor(prisma) {
        this.prisma = prisma;
    }
    async all() {
        const items = await this.prisma.supportTicket.findMany({ include: { user: { select: { id: true, fullName: true, matricNumber: true } } }, orderBy: { createdAt: 'desc' } });
        return (0, envelope_1.ok)(items);
    }
    async update(ticketId, dto) {
        const t = await this.prisma.supportTicket.update({ where: { id: ticketId }, data: { status: dto.status, adminNote: dto.adminNote } });
        return (0, envelope_1.ok)(t);
    }
};
exports.AdminSupportController = AdminSupportController;
__decorate([
    (0, common_1.Get)('tickets'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], AdminSupportController.prototype, "all", null);
__decorate([
    (0, common_1.Patch)('tickets/:ticketId'),
    __param(0, (0, common_1.Param)('ticketId')),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, UpdateTicketDto]),
    __metadata("design:returntype", Promise)
], AdminSupportController.prototype, "update", null);
exports.AdminSupportController = AdminSupportController = __decorate([
    (0, swagger_1.ApiTags)('Support (Admin)'),
    (0, swagger_1.ApiBearerAuth)(),
    (0, roles_decorator_1.Roles)(roles_1.UserRole.ADMIN, roles_1.UserRole.STAFF),
    (0, common_1.Controller)('admin/support'),
    __metadata("design:paramtypes", [prisma_service_1.PrismaService])
], AdminSupportController);
//# sourceMappingURL=support.controller.js.map