<?php

declare(strict_types=1);

defined('ABSPATH') || exit;

/**
 * Replaces the core `MeprRemindersCtrl` implementation.
 *
 * This will only be loaded if `app/controllers/MeprRemindersCtrl.php` does not exist.
 */
class MeprRemindersCtrl
{
    /**
     * Catch all removed static methods.
     *
     * @param string $method Method name.
     * @param array  $args   Arguments passed to method.
     *
     * @return mixed
     */
    public static function __callStatic(string $method, array $args)
    {
        $map = [];

        return self::map_magic_methods($method, $map);
    }

    /**
     * Catch all for removed non-static methods.
     *
     * @param string $method Method name.
     * @param array  $args   Arguments passed to method.
     *
     * @return mixed
     */
    public function __call(string $method, array $args)
    {
        $map = [
            'load_hooks'           => null,
            'schedule_reminder'    => null,
            'schedule_reminders'   => null,
            'unschedule_reminder'  => null,
            'unschedule_reminders' => null,
            'columns'              => [],
            'custom_columns'       => null,
            'register_post_type'   => null,
            'add_meta_boxes'       => null,
            'enqueue_scripts'      => null,
            'trigger_meta_box'     => null,
            'emails_meta_box'      => null,
            'save_postdata'        => null,
            'intervals'            => [],
            'get_valid_reminder'   => 0,
            'worker'               => null,
            'send_reminders'       => null,
            'delete'               => null,
        ];

        return self::map_magic_methods($method, $map);
    }

    /**
     * Map non-existing methods to catch-all map.
     *
     * @param  string $method Method name to map.
     * @param  array  $map    Map of method names and their return values.
     * @return mixed
     *
     * @throws MeprException If $method is not in $map.
     */
    private static function map_magic_methods(string $method, array $map)
    {
        if (array_key_exists($method, $map)) {
            return $map[$method];
        }

        throw new MeprException(
            esc_html(
                sprintf(
                    '%s::%s is not available in this edition of %s.',
                    __CLASS__,
                    $method,
                    MEPR_DISPLAY_NAME
                )
            )
        );
    }
}
