"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.ShopController = void 0;
const common_1 = require("@nestjs/common");
const shop_service_1 = require("./shop.service");
const swagger_1 = require("@nestjs/swagger");
let ShopController = class ShopController {
    constructor(ShopService) {
        this.ShopService = ShopService;
    }
    async searchShops(search, lang = 'en') {
        const term = (search || '').trim();
        if (!term || term.length < 3) {
            throw new common_1.BadRequestException('Search text must be at least 3 characters');
        }
        const shops = await this.ShopService.findActiveSearch(lang, term);
        return {
            status: true,
            message: 'Shop search list.',
            data: shops,
        };
    }
    async getAllCities() {
        try {
            const cities = await this.ShopService.getAllCities();
            return {
                status: true,
                message: 'City list.',
                data: cities,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findFeatured(query, lang) {
        try {
            const filters = { status: 'active', is_featured: 1 };
            const Offerid = query.Offerid;
            const list_type = "";
            const shops = await this.ShopService.findActive(lang, filters, list_type, Offerid);
            return {
                status: true,
                message: "featured Shop list.",
                data: shops,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findOne(id, lang) {
        try {
            const shop = await this.ShopService.findOne(+id, lang);
            return {
                status: true,
                message: "Shop details.",
                data: shop,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
    async findActive(query, lang) {
        try {
            const filters = { status: 'active' };
            if (query.cat) {
                filters.categoryId = query.cat;
            }
            if (query.is_featured) {
                filters.is_featured = Number(query.is_featured);
            }
            const list_type = query.list_type;
            const type = query.type;
            const Offerid = query.Offerid;
            const latitude = query.latitude ? parseFloat(query.latitude) : null;
            const longitude = query.longitude ? parseFloat(query.longitude) : null;
            const radius = query.radius ? parseFloat(query.radius) : 5;
            const latestType = query.latestType || null;
            const city = query.city || null;
            const shops = await this.ShopService.findActive(lang, filters, list_type, Offerid, latitude, longitude, radius, latestType, city);
            return {
                status: true,
                message: "Shop list.",
                data: shops,
            };
        }
        catch (error) {
            throw new common_1.BadRequestException(error.message);
        }
    }
};
exports.ShopController = ShopController;
__decorate([
    (0, common_1.Get)('search'),
    __param(0, (0, common_1.Query)('search')),
    __param(1, (0, common_1.Headers)('lang')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", Promise)
], ShopController.prototype, "searchShops", null);
__decorate([
    (0, common_1.Get)('cities'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], ShopController.prototype, "getAllCities", null);
__decorate([
    (0, common_1.Get)('featured'),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Headers)('lang')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], ShopController.prototype, "findFeatured", null);
__decorate([
    (0, common_1.Get)(":id"),
    __param(0, (0, common_1.Param)("id")),
    __param(1, (0, common_1.Headers)('lang')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, String]),
    __metadata("design:returntype", Promise)
], ShopController.prototype, "findOne", null);
__decorate([
    (0, common_1.Get)(),
    (0, swagger_1.ApiQuery)({ name: 'cat', required: false, type: String }),
    (0, swagger_1.ApiQuery)({ name: 'city', required: false, type: String }),
    (0, swagger_1.ApiQuery)({ name: 'service', required: false, type: String }),
    (0, swagger_1.ApiQuery)({ name: 'coupon', required: false, type: String }),
    (0, swagger_1.ApiQuery)({ name: 'is_featured', required: false, type: Number }),
    (0, swagger_1.ApiQuery)({ name: 'type', required: false, type: String }),
    (0, swagger_1.ApiQuery)({ name: 'radius', required: false, type: Number, default: 5 }),
    (0, swagger_1.ApiQuery)({ name: 'timing_open_close', required: false, type: String }),
    (0, swagger_1.ApiQuery)({ name: 'list_type', required: false, type: String, default: "offer" }),
    (0, swagger_1.ApiQuery)({ name: 'Offerid', required: false, type: String }),
    (0, swagger_1.ApiQuery)({ name: 'latitude', required: false, type: Number }),
    (0, swagger_1.ApiQuery)({ name: 'longitude', required: false, type: Number }),
    (0, swagger_1.ApiQuery)({ name: 'latestType', required: false, type: String }),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Headers)('lang')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], ShopController.prototype, "findActive", null);
exports.ShopController = ShopController = __decorate([
    (0, common_1.Controller)("app/shop"),
    __metadata("design:paramtypes", [shop_service_1.ShopService])
], ShopController);
//# sourceMappingURL=shop.controller.js.map