<?php

namespace Booktics\Calendar;

use Booktics\Contracts\Hookable_Service_Contract;

class Calendar_Registry implements Hookable_Service_Contract {
    private static $calendars = array();

    /**
     * Register a calendar service
     *
     * @param string $class
     *
     * @return void
     */
    public static function register_calendar( string $class ): void {
        if ( is_subclass_of( $class, Calendar_Interface::class ) ) {
            $calendar_id                     = $class::get_id();
            self::$calendars[ $calendar_id ] = $class;
        }
    }

    /**
     * Get a calendar instance by ID
     *
     * @param string $calendar_id
     *
     * @return Calendar_Interface|null
     */
    public static function get_calendar( string $calendar_id ): ?Calendar_Interface {
        $class = self::$calendars[ $calendar_id ] ?? null;

        return $class ? new $class() : null;
    }

    /**
     * Get all registered calendar IDs
     *
     * @return array
     */
    public static function get_available_calendars(): array {
        return array_keys( self::$calendars );
    }

    /**
     * Register the service
     *
     * @return void
     */
    public function register() {
        // Register any core calendars here if needed
    }
}
