<?php

/**
 * Custom Post Types Loader
 * Laurent-Perrier Theme
 *
 * This file loads all custom post type definitions from the post-types directory
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Load all custom post type files
 */
function lp_load_custom_post_types()
{
    $post_types_dir = get_template_directory() . '/includes/post-types/';

    // Array of post type files to load
    $post_type_files = array(
        'guides.php',
        // 'vins.php',
        // 'la-maison.php',
        // 'disclaimer.php',
    );

    // Load each post type file
    foreach ($post_type_files as $file) {
        $file_path = $post_types_dir . $file;
        if (file_exists($file_path)) {
            require_once $file_path;
        }
    }
}

// Load all custom post types
lp_load_custom_post_types();

/**
 * Flush rewrite rules on theme activation
 * This should be called manually when needed, not on every page load
 */
function lp_flush_rewrite_rules_on_activation()
{
    // Load post types first
    lp_load_custom_post_types();

    // Flush rewrite rules
    flush_rewrite_rules();
}

/**
 * Helper function to get all registered custom post types
 * Useful for debugging or admin purposes
 */
function lp_get_custom_post_types()
{
    return array(
        'guides' => array(
            'name' => 'Guides',
            'slug' => 'guides',
            'file' => 'guides.php'
        ),
        'vins' => array(
            'name' => 'Champagnes',
            'slug' => 'vins',
            'file' => 'vins.php'
        ),
        'la-maison' => array(
            'name' => 'La Maison',
            'slug' => 'la-maison',
            'file' => 'la-maison.php'
        ),
        'disclaimer' => array(
            'name' => 'Pays',
            'slug' => 'pays',
            'file' => 'disclaimer.php'
        ),
    );
}
