getInputs(); $id = $inputs['appointment_id'] ?? '?'; $when = trim( ( $inputs['date'] ?? '' ) . ' ' . ( $inputs['start_time'] ?? '' ) ); // Resolve so the approver can confirm which appointment moves. $detail = $this->describe_appointment( $inputs['appointment_id'] ?? 0 ); return '' !== $detail ? "Reschedule appointment #{$id} ({$detail}) to {$when}" : "Reschedule appointment #{$id} to {$when}"; } /** * Human-readable inputs shown in the approval card table. * * @return array */ public function get_approval_inputs(): array { $inputs = $this->getInputs(); // Surface who/what/when it moves from. $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 $date New date (Y-m-d). * @param string $start_time New start time (HH:MM). * @param string $end_time New end time (HH:MM). * @return array */ public function __invoke( int $appointment_id, string $date, string $start_time, string $end_time ): array { $check = $this->guard_staff(); if ( $check ) { return $check; } $access = $this->assert_appointment_access( $appointment_id ); if ( $access ) { return $access; } $datetime_error = $this->validate_appointment_datetime( $date, $start_time, $end_time ); if ( $datetime_error ) { return $datetime_error; } try { $body = [ 'date' => $date, 'start_time' => $start_time, 'end_time' => $end_time, ]; $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 reschedule appointment.' ); if ( isset( $data['error'] ) ) { return $data; } return [ 'success' => true, 'appointment_id' => $appointment_id, 'date' => $date, 'start_time' => $start_time, 'end_time' => $end_time, 'message' => "Appointment #{$appointment_id} rescheduled to {$date} {$start_time}–{$end_time}.", ]; } catch ( \Throwable $e ) { Log::error( 'Booktics_Reschedule_Appointment_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to reschedule appointment: ' . $e->getMessage() ]; } } }