"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.FavoriteController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const favorite_service_1 = require("./favorite.service");
const favorite_dto_1 = require("./favorite.dto");
const JwtAuthGuard_1 = require("../user/auth/JwtAuthGuard");
let FavoriteController = class FavoriteController {
    constructor(FavoriteService) {
        this.FavoriteService = FavoriteService;
    }
    async create(createFavoriteDto) {
        try {
            const res = await this.FavoriteService.create(createFavoriteDto);
            return {
                status: true,
                message: "Favorite Successfully created.",
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findAll(shopId) {
        try {
            const favorites = await this.FavoriteService.findAll(shopId);
            return {
                status: true,
                message: "Favorite list.",
                data: favorites,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findUserFavorite(userId) {
        try {
            const favorites = await this.FavoriteService.findUserFavorite(userId);
            return {
                status: true,
                message: "Favorite list.",
                data: favorites,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findOne(id) {
        try {
            const favorite = this.FavoriteService.findOne(+id);
            return {
                status: true,
                message: "Favorite detail.",
                data: favorite,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async remove(id) {
        try {
            const res = await this.FavoriteService.remove(+id);
            return {
                status: true,
                message: "Favorite Successfully deleted.",
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async addListingFavorite(dto, req) {
        try {
            const data = await this.FavoriteService.addListingFavorite(Number(req.user.userId), dto);
            return { status: true, message: "Added to favorites.", data };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async removeListingFavorite(listingType, listingId, req) {
        try {
            await this.FavoriteService.removeListingFavorite(Number(req.user.userId), listingType, Number(listingId));
            return { status: true, message: "Removed from favorites." };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async checkListingFavorite(listingType, listingId, req) {
        try {
            const data = await this.FavoriteService.checkListingFavorite(Number(req.user.userId), listingType, Number(listingId));
            return { status: true, data };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findMyListingFavorites(req, listingType) {
        try {
            const data = await this.FavoriteService.findUserListingFavorites(Number(req.user.userId), listingType);
            return { status: true, message: "Favorites list.", data };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
};
exports.FavoriteController = FavoriteController;
__decorate([
    (0, common_1.Post)(),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [favorite_dto_1.CreateFavoriteDto]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "create", null);
__decorate([
    (0, common_1.Get)(":shopId"),
    __param(0, (0, common_1.Param)("shopId")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "findAll", null);
__decorate([
    (0, common_1.Get)("user/:userId"),
    __param(0, (0, common_1.Param)("userId")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "findUserFavorite", null);
__decorate([
    (0, common_1.Get)(":id"),
    __param(0, (0, common_1.Param)("id")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "findOne", null);
__decorate([
    (0, common_1.Delete)(":id"),
    __param(0, (0, common_1.Param)("id")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "remove", null);
__decorate([
    (0, common_1.Post)("listing"),
    (0, swagger_1.ApiOperation)({ summary: "Add a car or plate listing to favorites" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [favorite_dto_1.CreateListingFavoriteDto, Object]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "addListingFavorite", null);
__decorate([
    (0, common_1.Delete)("listing/:listingType/:listingId"),
    (0, swagger_1.ApiOperation)({ summary: "Remove a car or plate listing from favorites" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __param(0, (0, common_1.Param)("listingType")),
    __param(1, (0, common_1.Param)("listingId")),
    __param(2, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "removeListingFavorite", null);
__decorate([
    (0, common_1.Get)("listing/:listingType/:listingId/check"),
    (0, swagger_1.ApiOperation)({ summary: "Check if a car or plate listing is in the user's favorites" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __param(0, (0, common_1.Param)("listingType")),
    __param(1, (0, common_1.Param)("listingId")),
    __param(2, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "checkListingFavorite", null);
__decorate([
    (0, common_1.Get)("me/listings"),
    (0, swagger_1.ApiOperation)({ summary: "Get the authenticated user's favorited car and plate listings" }),
    (0, swagger_1.ApiQuery)({ name: "listingType", required: false, enum: ["car", "plate"], example: "car" }),
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    __param(0, (0, common_1.Req)()),
    __param(1, (0, common_1.Query)("listingType")),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], FavoriteController.prototype, "findMyListingFavorites", null);
exports.FavoriteController = FavoriteController = __decorate([
    (0, swagger_1.ApiTags)("Favorites"),
    (0, common_1.Controller)("app/favorite"),
    __metadata("design:paramtypes", [favorite_service_1.FavoriteService])
], FavoriteController);
//# sourceMappingURL=favorite.controller.js.map