getInputs(); $id = $inputs['appointment_id'] ?? '?'; // Resolve so the approver sees which booking, not just a bare ID. $detail = $this->describe_appointment( $inputs['appointment_id'] ?? 0 ); $summary = '' !== $detail ? "Cancel appointment #{$id} — {$detail}" : "Cancel appointment #{$id}"; if ( ! empty( $inputs['cancel_note'] ) ) { $summary .= " (reason: {$inputs['cancel_note']})"; } return $summary; } /** * Human-readable inputs shown in the approval card table. * * @return array */ public function get_approval_inputs(): array { $inputs = $this->getInputs(); // Surface who/what/when for the approver. $detail = $this->describe_appointment( $inputs['appointment_id'] ?? 0 ); if ( '' !== $detail ) { $inputs['appointment'] = $detail; } return $inputs; } /** * Execute the tool after human approval. * * @param int $appointment_id Appointment ID. * @param string|null $cancel_note Optional cancellation note. * @return array */ public function __invoke( int $appointment_id, ?string $cancel_note = null ): array { $check = $this->guard_staff(); if ( $check ) { return $check; } $access = $this->assert_appointment_access( $appointment_id ); if ( $access ) { return $access; } try { $body = [ 'status' => 'canceled' ]; if ( null !== $cancel_note && '' !== trim( $cancel_note ) ) { $body['cancel_note'] = sanitize_text_field( $cancel_note ); } $request = $this->build_json_request( 'PUT', '/booktics/v1/appointments/' . $appointment_id, $body, $appointment_id ); if ( is_array( $request ) ) { return $request; } $controller = new \Booktics\Appointment\Controllers\Appointment_Controller(); $data = $this->extract_response( $controller->update_item( $request ), 'Failed to cancel appointment.' ); if ( isset( $data['error'] ) ) { return $data; } return [ 'success' => true, 'appointment_id' => $appointment_id, 'status' => 'canceled', 'message' => "Appointment #{$appointment_id} has been cancelled.", ]; } catch ( \Throwable $e ) { Log::error( 'Booktics_Cancel_Appointment_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to cancel appointment: ' . $e->getMessage() ]; } } }