"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.NumberPlateController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const numberplate_dto_1 = require("./numberplate.dto");
const numberplate_service_1 = require("./numberplate.service");
const JwtAuthGuard_1 = require("../user/auth/JwtAuthGuard");
const KycVerifiedGuard_1 = require("../../guards/KycVerifiedGuard");
let NumberPlateController = class NumberPlateController {
    constructor(numberPlateService) {
        this.numberPlateService = numberPlateService;
    }
    async createListing(body, req) {
        try {
            const data = await this.numberPlateService.createListing(body, Number(req.user.userId));
            return {
                status: true,
                message: "License plate listing created.",
                data,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findMarketplaceListings(query) {
        try {
            const data = await this.numberPlateService.findMarketplaceListings(query);
            return {
                status: true,
                message: "License plate marketplace list.",
                data: data.map((listing) => this.numberPlateService.decorateListing(listing)),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findSellerListings(sellerUserId) {
        try {
            const data = await this.numberPlateService.findSellerListings(Number(sellerUserId));
            return {
                status: true,
                message: "Seller license plate listing list.",
                data: data.map((listing) => this.numberPlateService.decorateListing(listing)),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findMyListings(req) {
        try {
            const data = await this.numberPlateService.findSellerListings(Number(req.user.userId));
            return {
                status: true,
                message: "My license plate listing list.",
                data: data.map((listing) => this.numberPlateService.decorateListing(listing)),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    getConfig() {
        try {
            return {
                status: true,
                message: "Number plate configuration.",
                data: this.numberPlateService.getConfig(),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    preview(query) {
        try {
            const data = this.numberPlateService.generatePreview(query);
            return {
                status: true,
                message: "Number plate preview generated.",
                data,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    getCarAssets() {
        return {
            status: true,
            data: this.numberPlateService.getCarAssets(),
        };
    }
    async carPreview(query) {
        try {
            const data = await this.numberPlateService.generateCarPreview(query);
            return {
                status: true,
                message: "Car number plate preview generated.",
                data,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async getListingCarPreview(id, req) {
        try {
            const data = await this.numberPlateService.getListingPreview(Number(id), Number(req.user.userId));
            return {
                status: true,
                message: "Car number plate preview generated.",
                data,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findListing(id, req) {
        try {
            const data = await this.numberPlateService.findListing(Number(id), Number(req.user.userId));
            return {
                status: true,
                message: "License plate listing detail.",
                data: this.numberPlateService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async updateListing(id, body, req) {
        try {
            const data = await this.numberPlateService.updateListing(Number(id), body, Number(req.user.userId));
            return {
                status: true,
                message: "License plate listing updated.",
                data: this.numberPlateService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async markSold(id, body, req) {
        try {
            const data = await this.numberPlateService.markSold(Number(id), body, Number(req.user.userId));
            return {
                status: true,
                message: "License plate marked as sold.",
                data: this.numberPlateService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async updateListingStatus(id, body, req) {
        try {
            const data = await this.numberPlateService.updateListingStatus(Number(id), body, Number(req.user.userId));
            return {
                status: true,
                message: "License plate listing status updated.",
                data: this.numberPlateService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async removeListing(id, req) {
        try {
            const data = await this.numberPlateService.removeListing(Number(id), Number(req.user.userId));
            return {
                status: true,
                message: "License plate listing deleted.",
                data: this.numberPlateService.decorateListing(data),
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
};
exports.NumberPlateController = NumberPlateController;
__decorate([
    (0, common_1.Post)(),
    (0, swagger_1.ApiOperation)({ summary: "Create a license plate marketplace listing" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard, KycVerifiedGuard_1.KycVerifiedGuard),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [numberplate_dto_1.CreateNumberPlateListingDto, Object]),
    __metadata("design:returntype", Promise)
], NumberPlateController.prototype, "createListing", null);
__decorate([
    (0, common_1.Get)(),
    (0, swagger_1.ApiOperation)({ summary: "List license plates available in the marketplace" }),
    (0, swagger_1.ApiQuery)({ name: "emirate", required: false, example: "dubai" }),
    (0, swagger_1.ApiQuery)({ name: "minPrice", required: false, example: "1000" }),
    (0, swagger_1.ApiQuery)({ name: "maxPrice", required: false, example: "50000" }),
    (0, swagger_1.ApiQuery)({ name: "status", required: false, example: "active" }),
    (0, swagger_1.ApiQuery)({ name: "code", required: false, example: "NOC" }),
    (0, swagger_1.ApiQuery)({ name: "digitCount", required: false, example: "5" }),
    (0, swagger_1.ApiQuery)({ name: "plateType", required: false, enum: numberplate_dto_1.NumberPlateType, example: numberplate_dto_1.NumberPlateType.BIKE }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [numberplate_dto_1.NumberPlateMarketplaceQueryDto]),
    __metadata("design:returntype", Promise)
], NumberPlateController.prototype, "findMarketplaceListings", null);
__decorate([
    (0, common_1.Get)("seller/:sellerUserId"),
    (0, swagger_1.ApiOperation)({ summary: "List license plates created by a seller" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __param(0, (0, common_1.Param)("sellerUserId")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Promise)
], NumberPlateController.prototype, "findSellerListings", null);
__decorate([
    (0, common_1.Get)("me"),
    (0, swagger_1.ApiOperation)({ summary: "List the authenticated user's license plate listings" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __param(0, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], NumberPlateController.prototype, "findMyListings", null);
__decorate([
    (0, common_1.Get)("config"),
    (0, swagger_1.ApiOperation)({ summary: "Get supported number plate emirates, designs, and codes" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], NumberPlateController.prototype, "getConfig", null);
__decorate([
    (0, common_1.Get)("preview"),
    (0, swagger_1.ApiOperation)({ summary: "Generate UAE number plate preview URL (car or bike)" }),
    (0, swagger_1.ApiQuery)({ name: "vehicleType", required: false, enum: ["car", "bike"], example: "car" }),
    (0, swagger_1.ApiQuery)({ name: "emirate", required: true, example: "abu-dhabi" }),
    (0, swagger_1.ApiQuery)({ name: "design", required: false, example: "normal" }),
    (0, swagger_1.ApiQuery)({ name: "code", required: false, example: "NOC", description: "Car plates only" }),
    (0, swagger_1.ApiQuery)({ name: "number", required: true, example: "6261" }),
    (0, swagger_1.ApiQuery)({ name: "flag1", required: false, enum: ["0", "1"], example: "0" }),
    (0, swagger_1.ApiQuery)({ name: "flag2", required: false, enum: ["0", "1"], example: "0" }),
    (0, swagger_1.ApiQuery)({ name: "width", required: false, example: "300" }),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [numberplate_dto_1.NumberPlatePreviewQueryDto]),
    __metadata("design:returntype", void 0)
], NumberPlateController.prototype, "preview", null);
__decorate([
    (0, common_1.Get)("car-assets"),
    (0, swagger_1.ApiOperation)({ summary: "List available car slugs for plate preview generation" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], NumberPlateController.prototype, "getCarAssets", null);
__decorate([
    (0, common_1.Get)("car-preview"),
    (0, swagger_1.ApiOperation)({ summary: "Generate front/back preview images composited onto a vehicle background" }),
    (0, swagger_1.ApiQuery)({ name: "plateImageUrl", required: false, example: "https://xplate.io/en/numbers/images/license-plate/dubai-classic/NOC/99899/0/0/1200", description: "Direct plate image URL. Omit to build from vehicleType/emirate/code/number." }),
    (0, swagger_1.ApiQuery)({ name: "vehicleType", required: false, enum: ["car", "bike"], example: "bike" }),
    (0, swagger_1.ApiQuery)({ name: "emirate", required: false, example: "abu-dhabi" }),
    (0, swagger_1.ApiQuery)({ name: "design", required: false, example: "normal" }),
    (0, swagger_1.ApiQuery)({ name: "code", required: false, example: "7" }),
    (0, swagger_1.ApiQuery)({ name: "number", required: false, example: "2131" }),
    (0, swagger_1.ApiQuery)({ name: "width", required: false, example: "1200" }),
    (0, swagger_1.ApiQuery)({ name: "expandRatio", required: false, example: "1.01" }),
    (0, swagger_1.ApiQuery)({ name: "publicBaseUrl", required: false, example: "https://api.cars247.ae" }),
    (0, swagger_1.ApiQuery)({ name: "drawBox", required: false, example: "true" }),
    (0, swagger_1.ApiQuery)({ name: "offsetY", required: false, example: "24" }),
    (0, swagger_1.ApiQuery)({ name: "carSlug", required: false, example: "kawasaki" }),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [numberplate_dto_1.NumberPlateCarPreviewQueryDto]),
    __metadata("design:returntype", Promise)
], NumberPlateController.prototype, "carPreview", null);
__decorate([
    (0, common_1.Get)(":id/car-preview"),
    (0, swagger_1.ApiOperation)({ summary: "Get the stored front/back preview assets for a plate listing" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __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)
], NumberPlateController.prototype, "getListingCarPreview", null);
__decorate([
    (0, common_1.Get)(":id"),
    (0, swagger_1.ApiOperation)({ summary: "Get license plate listing detail" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __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)
], NumberPlateController.prototype, "findListing", null);
__decorate([
    (0, common_1.Patch)(":id"),
    (0, swagger_1.ApiOperation)({ summary: "Update a license plate listing" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __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.UpdateNumberPlateListingDto, Object]),
    __metadata("design:returntype", Promise)
], NumberPlateController.prototype, "updateListing", null);
__decorate([
    (0, common_1.Patch)(":id/sold"),
    (0, swagger_1.ApiOperation)({ summary: "Mark a license plate listing as sold" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __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.MarkNumberPlateSoldDto, Object]),
    __metadata("design:returntype", Promise)
], NumberPlateController.prototype, "markSold", null);
__decorate([
    (0, common_1.Patch)(":id/status"),
    (0, swagger_1.ApiOperation)({ summary: "Pause or resume a license plate listing" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __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.UpdateNumberPlateListingStatusDto, Object]),
    __metadata("design:returntype", Promise)
], NumberPlateController.prototype, "updateListingStatus", null);
__decorate([
    (0, common_1.Delete)(":id"),
    (0, swagger_1.ApiOperation)({ summary: "Delete a license plate listing" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __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)
], NumberPlateController.prototype, "removeListing", null);
exports.NumberPlateController = NumberPlateController = __decorate([
    (0, swagger_1.ApiTags)("Number Plate Marketplace"),
    (0, common_1.Controller)("app/number-plates"),
    __metadata("design:paramtypes", [numberplate_service_1.NumberPlateService])
], NumberPlateController);
//# sourceMappingURL=numberplate.controller.js.map