const Banner = require('../models/Banner');
const FAQ = require('../models/FAQ');
const Footer = require('../models/Footer');

/**
 * Get all active banners ordered by 'order' field
 */
const getBanners = async () => {
    return await Banner.find({ isActive: true }).sort({ order: 1 });
};

/**
 * Get all active FAQs ordered by 'order' field
 */
const getFAQs = async () => {
    return await FAQ.find({ isActive: true }).sort({ order: 1 });
};

/**
 * Get all active Footer sections ordered by 'order' field
 */
const getFooter = async () => {
    return await Footer.find({ isActive: true }).sort({ order: 1 });
};

// ==========================================
// ADMIN IMPLEMENTATIONS
// ==========================================

// --- Banners ---
const createBanner = async (data) => {
    return await Banner.create(data);
};

const updateBanner = async (id, data) => {
    return await Banner.findByIdAndUpdate(id, data, { new: true });
};

const deleteBanner = async (id) => {
    return await Banner.findByIdAndDelete(id);
};

// --- FAQs ---
const createFAQ = async (data) => {
    return await FAQ.create(data);
};

const updateFAQ = async (id, data) => {
    return await FAQ.findByIdAndUpdate(id, data, { new: true });
};

const deleteFAQ = async (id) => {
    return await FAQ.findByIdAndDelete(id);
};

// --- Footer ---
const createFooterSection = async (data) => {
    return await Footer.create(data);
};

const updateFooterSection = async (id, data) => {
    return await Footer.findByIdAndUpdate(id, data, { new: true });
};

const deleteFooterSection = async (id) => {
    return await Footer.findByIdAndDelete(id);
};

module.exports = {
    getBanners,
    getFAQs,
    getFooter,
    createBanner,
    updateBanner,
    deleteBanner,
    createFAQ,
    updateFAQ,
    deleteFAQ,
    createFooterSection,
    updateFooterSection,
    deleteFooterSection
};
