"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.AdminNumberPlateController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const numberplate_dto_1 = require("../../appapi/numberplate/numberplate.dto");
const numberplate_service_1 = require("../../appapi/numberplate/numberplate.service");
const JwtAuthGuard_1 = require("../../guards/JwtAuthGuard");
const roles_guard_1 = require("../../appapi/user/auth/roles.guard");
const roles_decorator_1 = require("../../appapi/user/auth/roles.decorator");
const user_entity_1 = require("../../appapi/user/user.entity");
let AdminNumberPlateController = class AdminNumberPlateController {
    constructor(numberPlateService) {
        this.numberPlateService = numberPlateService;
    }
    async findListings(query) {
        try {
            const data = await this.numberPlateService.adminFindListings(query);
            return {
                status: true,
                message: "Number plate marketplace listing list.",
                data: data.map((listing) => this.numberPlateService.decorateListing(listing)),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findListing(id) {
        try {
            const data = await this.numberPlateService.findListing(Number(id), undefined, true);
            return {
                status: true,
                message: "Number plate marketplace listing detail.",
                data: this.numberPlateService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async moderateListing(id, body, req) {
        try {
            const adminUserId = Number(req?.user?.userId || 0);
            const data = await this.numberPlateService.adminModerateListing(Number(id), adminUserId, body);
            return {
                status: true,
                message: "Number plate marketplace listing updated.",
                data: this.numberPlateService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
};
exports.AdminNumberPlateController = AdminNumberPlateController;
__decorate([
    (0, common_1.Get)(),
    (0, swagger_1.ApiOperation)({ summary: "List all number plate marketplace listings for admin" }),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], AdminNumberPlateController.prototype, "findListings", null);
__decorate([
    (0, common_1.Get)(":id"),
    (0, swagger_1.ApiOperation)({ summary: "Get number plate marketplace listing detail for admin" }),
    __param(0, (0, common_1.Param)("id")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Promise)
], AdminNumberPlateController.prototype, "findListing", null);
__decorate([
    (0, common_1.Patch)(":id/moderation"),
    (0, swagger_1.ApiOperation)({ summary: "Approve, reject, extend, or hide a number plate listing" }),
    __param(0, (0, common_1.Param)("id")),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, numberplate_dto_1.AdminNumberPlateModerationDto, Object]),
    __metadata("design:returntype", Promise)
], AdminNumberPlateController.prototype, "moderateListing", null);
exports.AdminNumberPlateController = AdminNumberPlateController = __decorate([
    (0, swagger_1.ApiTags)("Admin Number Plate Marketplace"),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard, roles_guard_1.RolesGuard),
    (0, roles_decorator_1.Roles)(user_entity_1.UserRole.ADMIN),
    (0, common_1.Controller)("admin/number-plates"),
    __metadata("design:paramtypes", [numberplate_service_1.NumberPlateService])
], AdminNumberPlateController);
//# sourceMappingURL=admin.numberplate.controller.js.map