<?php

namespace Booktics\Calendar;

class Calendar_Manager {
    public static function sync_team_member_calendar( int $team_member_id, string $calendar_id ): array {
        if ( $calendar = Calendar_Registry::get_calendar( $calendar_id ) ) {
            if ( $calendar->is_configured( $team_member_id ) ) {
                return $calendar->sync_events( $team_member_id );
            }
            throw new \Exception(
                sprintf(
                    'Calendar not configured for team member ID: %d',
                    intval( $team_member_id )
                )
            );
        }
        throw new \Exception( sprintf( 'Calendar not found: %s', esc_html( $calendar_id ) ) );
    }

    public static function create_calendar_event( string $calendar_id, int $team_member_id, array $event_data ): bool {
        if ( $calendar = Calendar_Registry::get_calendar( $calendar_id ) ) {
            return $calendar->create_event( array_merge( $event_data, array( 'team_member_id' => $team_member_id ) ) );
        }
        return false;
    }
}
