"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.CarListingController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const car_listing_dto_1 = require("./car-listing.dto");
const car_listing_service_1 = require("./car-listing.service");
const JwtAuthGuard_1 = require("../user/auth/JwtAuthGuard");
const KycVerifiedGuard_1 = require("../../guards/KycVerifiedGuard");
let CarListingController = class CarListingController {
    constructor(carListingService) {
        this.carListingService = carListingService;
    }
    async getConfig(page, limit) {
        const pageNum = page ? Number(page) : undefined;
        const limitNum = limit ? Number(limit) : undefined;
        return {
            status: true,
            message: "Car marketplace configuration.",
            data: await this.carListingService.getConfig(pageNum, limitNum),
        };
    }
    async getCatalogEntry(make, model, year) {
        try {
            const yearNum = Number(year);
            if (!make || !model || !Number.isFinite(yearNum)) {
                throw new common_1.BadRequestException("make, model, and year are required.");
            }
            const data = await this.carListingService.getCatalogEntryDefaults(make, model, yearNum);
            return {
                status: true,
                message: "Car catalog entry defaults.",
                data,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async createListing(body, req) {
        try {
            const data = await this.carListingService.createListing(Number(req.user.userId), body);
            return {
                status: true,
                message: "Car listing created.",
                data: this.carListingService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findListings(query) {
        try {
            const data = await this.carListingService.findMarketplaceListings(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 findMyListings(req) {
        try {
            const data = await this.carListingService.findMyListings(Number(req.user.userId));
            return {
                status: true,
                message: "My car marketplace listings.",
                data: data.map((listing) => this.carListingService.decorateListing(listing)),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findListing(id, req) {
        try {
            const data = await this.carListingService.findListing(Number(id), Number(req.user.userId));
            return {
                status: true,
                message: "Car marketplace listing detail.",
                data: this.carListingService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async updateListing(id, body, req) {
        try {
            const data = await this.carListingService.updateListing(Number(id), Number(req.user.userId), body);
            return {
                status: true,
                message: "Car marketplace listing updated.",
                data: this.carListingService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async updateListingStatus(id, body, req) {
        try {
            const data = await this.carListingService.updateListingStatus(Number(id), Number(req.user.userId), body);
            return {
                status: true,
                message: "Car marketplace listing status updated.",
                data: this.carListingService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async removeListing(id, req) {
        try {
            const data = await this.carListingService.removeListing(Number(id), Number(req.user.userId));
            return {
                status: true,
                message: "Car marketplace listing deleted.",
                data: this.carListingService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
};
exports.CarListingController = CarListingController;
__decorate([
    (0, common_1.Get)("config"),
    (0, swagger_1.ApiQuery)({ name: "page", required: false, type: Number }),
    (0, swagger_1.ApiQuery)({ name: "limit", required: false, type: Number }),
    (0, swagger_1.ApiOperation)({ summary: "Get supported car makes, models, and years for listings" }),
    __param(0, (0, common_1.Query)("page")),
    __param(1, (0, common_1.Query)("limit")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "getConfig", null);
__decorate([
    (0, common_1.Get)("catalog-entry"),
    (0, swagger_1.ApiQuery)({ name: "make", required: true, type: String }),
    (0, swagger_1.ApiQuery)({ name: "model", required: true, type: String }),
    (0, swagger_1.ApiQuery)({ name: "year", required: true, type: Number }),
    (0, swagger_1.ApiOperation)({
        summary: "Get default listing details from the imported car catalog (make/model/year)",
    }),
    __param(0, (0, common_1.Query)("make")),
    __param(1, (0, common_1.Query)("model")),
    __param(2, (0, common_1.Query)("year")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, String]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "getCatalogEntry", null);
__decorate([
    (0, common_1.Post)(),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard, KycVerifiedGuard_1.KycVerifiedGuard),
    (0, swagger_1.ApiOperation)({ summary: "Create a car marketplace listing" }),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [car_listing_dto_1.CreateCarListingDto, Object]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "createListing", null);
__decorate([
    (0, common_1.Get)(),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, swagger_1.ApiOperation)({ summary: "List car marketplace listings" }),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [car_listing_dto_1.CarListingQueryDto]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "findListings", null);
__decorate([
    (0, common_1.Get)("me"),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, swagger_1.ApiOperation)({ summary: "List the authenticated user's car listings" }),
    __param(0, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "findMyListings", null);
__decorate([
    (0, common_1.Get)(":id"),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, swagger_1.ApiOperation)({ summary: "Get car marketplace listing detail" }),
    __param(0, (0, common_1.Param)("id")),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, Object]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "findListing", null);
__decorate([
    (0, common_1.Patch)(":id"),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, swagger_1.ApiOperation)({ summary: "Update a car marketplace 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.UpdateCarListingDto, Object]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "updateListing", null);
__decorate([
    (0, common_1.Patch)(":id/status"),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, swagger_1.ApiOperation)({ summary: "Pause, resume, or mark a car listing as sold" }),
    __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.UpdateCarListingStatusDto, Object]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "updateListingStatus", null);
__decorate([
    (0, common_1.Delete)(":id"),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, swagger_1.ApiOperation)({ summary: "Delete a car marketplace listing" }),
    __param(0, (0, common_1.Param)("id")),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, Object]),
    __metadata("design:returntype", Promise)
], CarListingController.prototype, "removeListing", null);
exports.CarListingController = CarListingController = __decorate([
    (0, swagger_1.ApiTags)("Car Marketplace"),
    (0, common_1.Controller)("app/car-listings"),
    __metadata("design:paramtypes", [car_listing_service_1.CarListingService])
], CarListingController);
//# sourceMappingURL=car-listing.controller.js.map