"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.listPublicBanners = exports.deleteAdminBanner = exports.updateAdminBanner = exports.createAdminBanner = exports.getAdminBannerById = exports.listAdminBanners = void 0;
const apiResponse_js_1 = require("../utils/apiResponse.js");
const bannerService = __importStar(require("../services/bannerService.js"));
const listAdminBanners = async (req, res) => {
    const query = req.validatedQuery;
    const result = await bannerService.listBanners(query);
    return (0, apiResponse_js_1.sendSuccess)(res, 200, result);
};
exports.listAdminBanners = listAdminBanners;
const getAdminBannerById = async (req, res) => {
    const { id } = req.validatedParams;
    const banner = await bannerService.getBannerById(id);
    if (!banner) {
        return (0, apiResponse_js_1.sendError)(res, 404, "BANNER_NOT_FOUND", "Banner not found.");
    }
    return (0, apiResponse_js_1.sendSuccess)(res, 200, banner);
};
exports.getAdminBannerById = getAdminBannerById;
const createAdminBanner = async (req, res) => {
    const input = req.validatedBody;
    const banner = await bannerService.createBanner(input);
    return (0, apiResponse_js_1.sendSuccess)(res, 201, banner, "Banner created.");
};
exports.createAdminBanner = createAdminBanner;
const updateAdminBanner = async (req, res) => {
    const { id } = req.validatedParams;
    const input = req.validatedBody;
    const existing = await bannerService.getBannerById(id);
    if (!existing) {
        return (0, apiResponse_js_1.sendError)(res, 404, "BANNER_NOT_FOUND", "Banner not found.");
    }
    const banner = await bannerService.updateBanner(id, input);
    return (0, apiResponse_js_1.sendSuccess)(res, 200, banner, "Banner updated.");
};
exports.updateAdminBanner = updateAdminBanner;
const deleteAdminBanner = async (req, res) => {
    const { id } = req.validatedParams;
    const existing = await bannerService.getBannerById(id);
    if (!existing) {
        return (0, apiResponse_js_1.sendError)(res, 404, "BANNER_NOT_FOUND", "Banner not found.");
    }
    await bannerService.deleteBanner(id);
    return (0, apiResponse_js_1.sendSuccess)(res, 200, null, "Banner deleted.");
};
exports.deleteAdminBanner = deleteAdminBanner;
const listPublicBanners = async (_req, res) => {
    const banners = await bannerService.listActiveBanners();
    return (0, apiResponse_js_1.sendSuccess)(res, 200, banners);
};
exports.listPublicBanners = listPublicBanners;
//# sourceMappingURL=bannerController.js.map