__( 'Prepare a brand change', 'addsynapse-store-assistant' ), 'description' => 'Plans setting, adding or removing the brand of the selected products, wherever this store keeps brands, and stores it as a DRAFT change set for the manager to approve. Changes nothing in the store.', 'category' => AbilitiesRegistrar::CATEGORY, 'input_schema' => self::input_schema(), 'execute_callback' => array( $this, 'execute' ), 'permission_callback' => array( AbilitiesRegistrar::class, 'can_manage' ), 'meta' => Shared::plan_meta(), ) ); } /** * Input schema (also the tool definition the AI provider receives). * * @return array */ public static function input_schema(): array { return array( 'type' => 'object', 'additionalProperties' => false, 'properties' => ProductSelector::schema_properties() + array( 'mode' => array( 'type' => 'string', 'enum' => self::MODES, 'default' => 'set', ), 'brand' => array( 'type' => 'string', 'minLength' => 1, 'maxLength' => 100, ), 'brand_id' => array( 'type' => 'integer', 'minimum' => 1, ), ), ); } /** * Execute callback. * * @param array $input Input. * @return array|WP_Error */ public function execute( $input = null ) { $input = is_array( $input ) ? $input : array(); $brand = trim( (string) ( $input['brand'] ?? '' ) ); $id = (int) ( $input['brand_id'] ?? 0 ); if ( '' === $brand && $id < 1 ) { return new WP_Error( 'addsynapse_assistant_invalid_plan', 'Give the brand: brand (name) or brand_id.' ); } $resolved = BrandResolver::resolve(); if ( is_wp_error( $resolved ) ) { return $resolved; } $adapter = $resolved['adapter']; $mode = (string) ( $input['mode'] ?? 'set' ); $terms = array_diff_key( $input, array_flip( array( 'brand', 'brand_id', 'mode' ) ) ); if ( $id > 0 ) { $terms['term_ids'] = array( $id ); } else { $terms['term_names'] = array( $brand ); } $terms['mode'] = 'set' === $mode ? 'replace' : $mode; return ( new TermsPlanner() )->plan( $terms, get_current_user_id(), ToolRegistry::current_conversation_id(), array( 'operation' => self::OPERATION, 'taxonomy' => $adapter->taxonomy(), 'warnings' => $resolved['warnings'], 'params' => array( 'brand_mode' => $mode, 'brand_adapter' => $adapter->key(), 'brand_storage' => $adapter->storage(), 'brand_plugin' => $adapter->label(), ), ) ); } }