"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.PublicController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const prisma_service_1 = require("../prisma/prisma.service");
const envelope_1 = require("../../common/envelope");
const public_decorator_1 = require("../../common/decorators/public.decorator");
let PublicController = class PublicController {
    constructor(prisma) {
        this.prisma = prisma;
    }
    health() { return (0, envelope_1.ok)({ status: 'ok' }); }
    home() {
        return (0, envelope_1.ok)({
            brand: { name: 'Almonan Institute', tagline: 'Learn online, excel offline.' },
            sections: ['Hero', 'Featured Courses', 'Library', 'Bookstore', 'Testimonials', 'FAQ'],
        });
    }
    async listCourses(q, category) {
        const where = { published: true };
        if (q)
            where.OR = [{ title: { contains: q, mode: 'insensitive' } }, { description: { contains: q, mode: 'insensitive' } }];
        if (category)
            where.category = category;
        const items = await this.prisma.course.findMany({ where, orderBy: { createdAt: 'desc' }, select: { id: true, title: true, description: true, price: true, currency: true, isFree: true, category: true, level: true, published: true } });
        return (0, envelope_1.ok)(items);
    }
    async library(q) {
        const where = { published: true, visibility: { in: ['library', 'both'] } };
        if (q)
            where.OR = [{ title: { contains: q, mode: 'insensitive' } }, { author: { contains: q, mode: 'insensitive' } }];
        const items = await this.prisma.libraryBook.findMany({ where, orderBy: { createdAt: 'desc' } });
        return (0, envelope_1.ok)(items);
    }
    async store(q) {
        const where = { active: true };
        if (q)
            where.OR = [{ title: { contains: q, mode: 'insensitive' } }, { author: { contains: q, mode: 'insensitive' } }];
        const items = await this.prisma.storeProduct.findMany({ where, orderBy: { createdAt: 'desc' } });
        return (0, envelope_1.ok)(items);
    }
};
exports.PublicController = PublicController;
__decorate([
    (0, public_decorator_1.Public)(),
    (0, common_1.Get)('health'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], PublicController.prototype, "health", null);
__decorate([
    (0, public_decorator_1.Public)(),
    (0, common_1.Get)('public/home'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], PublicController.prototype, "home", null);
__decorate([
    (0, public_decorator_1.Public)(),
    (0, common_1.Get)('public/courses'),
    __param(0, (0, common_1.Query)('q')),
    __param(1, (0, common_1.Query)('category')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", Promise)
], PublicController.prototype, "listCourses", null);
__decorate([
    (0, public_decorator_1.Public)(),
    (0, common_1.Get)('public/books/library'),
    __param(0, (0, common_1.Query)('q')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], PublicController.prototype, "library", null);
__decorate([
    (0, public_decorator_1.Public)(),
    (0, common_1.Get)('public/books/store'),
    __param(0, (0, common_1.Query)('q')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], PublicController.prototype, "store", null);
exports.PublicController = PublicController = __decorate([
    (0, swagger_1.ApiTags)('Public'),
    (0, common_1.Controller)(),
    __metadata("design:paramtypes", [prisma_service_1.PrismaService])
], PublicController);
//# sourceMappingURL=public.controller.js.map