-Duplicate". Useful as a starting point for a similar meeting. ' . 'Requires admin approval.' ); } protected function properties(): array { return [ new ToolProperty( name: 'meeting_id', type: PropertyType::NUMBER, description: 'The ID of the meeting to duplicate.', required: true ), ]; } public function get_approval_label(): string { return 'Duplicate Timetics Meeting'; } public function format_approval_summary(): string { $inputs = $this->getInputs(); $id = (int) ( $inputs['meeting_id'] ?? 0 ); $title = $id > 0 ? get_the_title( $id ) : ''; return '' !== $title ? "Duplicate meeting \"{$title}\" (ID: {$id})" : "Duplicate meeting #{$id}"; } public function get_approval_inputs(): array { $inputs = $this->getInputs(); if ( isset( $inputs['meeting_id'] ) ) { $id = (int) $inputs['meeting_id']; $title = get_the_title( $id ); $inputs['meeting_id'] = '' !== $title ? "{$title} (ID: {$id})" : (string) $id; } return $inputs; } public function __invoke( int $meeting_id ): array { $check = $this->guard_admin(); if ( $check ) { return $check; } if ( $meeting_id <= 0 ) { return [ 'error' => 'A valid meeting_id is required.' ]; } try { $request = $this->build_request( 'POST', '/timetics/v1/appointments/' . $meeting_id . '/duplicate', [], null, [ 'appointment_id' => $meeting_id ] ); if ( is_array( $request ) ) { return $request; } $controller = \Timetics\Core\Appointments\Api_Appointment::instance(); $data = $this->extract_response( $controller->duplicate_item( $request ), "Failed to duplicate meeting #{$meeting_id}." ); if ( isset( $data['error'] ) ) { return $data; } $new_id = (int) ( $data['id'] ?? 0 ); if ( $new_id <= 0 ) { Log::error( 'Timetics_Duplicate_Meeting_Tool got a success response without an ID', [ 'source_id' => $meeting_id ] ); return [ 'error' => 'The meeting may not have been duplicated; Timetics returned no ID. Please verify in Timetics before retrying.' ]; } return [ 'success' => true, 'source_id' => $meeting_id, 'new_meeting_id' => $new_id, 'meeting' => $this->shape_meeting( $data, true ), 'message' => "Meeting #{$meeting_id} duplicated successfully as meeting #{$new_id}.", ]; } catch ( \Throwable $e ) { Log::error( 'Timetics_Duplicate_Meeting_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to duplicate meeting: ' . $e->getMessage() ]; } } }