"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.AdminCarListingController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const car_listing_service_1 = require("../../appapi/carlisting/car-listing.service");
const car_listing_dto_1 = require("../../appapi/carlisting/car-listing.dto");
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 AdminCarListingController = class AdminCarListingController {
    constructor(carListingService) {
        this.carListingService = carListingService;
    }
    async findListings(query) {
        try {
            const data = await this.carListingService.adminFindListings(query);
            return {
                status: true,
                message: "Car marketplace listing list.",
                data: data.map((listing) => this.carListingService.decorateListing(listing)),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findListing(id) {
        try {
            const data = await this.carListingService.findListing(Number(id), undefined, true);
            return {
                status: true,
                message: "Car marketplace listing detail.",
                data: this.carListingService.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.carListingService.adminModerateListing(Number(id), adminUserId, body);
            return {
                status: true,
                message: "Car marketplace listing updated.",
                data: this.carListingService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
};
exports.AdminCarListingController = AdminCarListingController;
__decorate([
    (0, common_1.Get)(),
    (0, swagger_1.ApiOperation)({ summary: "List all car marketplace listings for admin" }),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], AdminCarListingController.prototype, "findListings", null);
__decorate([
    (0, common_1.Get)(":id"),
    (0, swagger_1.ApiOperation)({ summary: "Get car marketplace listing detail for admin" }),
    __param(0, (0, common_1.Param)("id")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Promise)
], AdminCarListingController.prototype, "findListing", null);
__decorate([
    (0, common_1.Patch)(":id/moderation"),
    (0, swagger_1.ApiOperation)({ summary: "Approve, reject, extend, or hide a car 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, car_listing_dto_1.AdminCarListingModerationDto, Object]),
    __metadata("design:returntype", Promise)
], AdminCarListingController.prototype, "moderateListing", null);
exports.AdminCarListingController = AdminCarListingController = __decorate([
    (0, swagger_1.ApiTags)("Admin Car 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/car-listings"),
    __metadata("design:paramtypes", [car_listing_service_1.CarListingService])
], AdminCarListingController);
//# sourceMappingURL=admin.car-listing.controller.js.map