array( 'type' => 'string', 'enum' => Entitlement_Repository::AI_TARGETS, 'description' => __( 'brand updates the brand record; query updates one monitored query; generate-queries appends new baseline queries and spends credits.', 'acrossai-abilities-manager' ), ), 'brand_id' => array( 'type' => 'integer', 'minimum' => 1 ), 'query_id' => array( 'type' => 'integer', 'minimum' => 1, 'description' => __( 'Required for target=query.', 'acrossai-abilities-manager' ) ), 'data' => array( 'type' => 'object', 'description' => __( 'Fields to write. Not needed for generate-queries.', 'acrossai-abilities-manager' ), 'additionalProperties' => true, ), ); } protected function output_properties(): array { return array( 'target' => array( 'type' => 'string' ), 'brand_id' => array( 'type' => 'integer' ), 'query_id' => array( 'type' => array( 'integer', 'null' ) ), 'result' => array( 'type' => array( 'object', 'array', 'null' ) ), ); } /** * 'confirm' is intentionally absent — see Base_Rank_Math_Ability::ability(). */ protected function required_input(): array { return array( 'target', 'brand_id' ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => true, 'idempotent' => false ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $result = Entitlement_Repository::update_ai_object( isset( $input['target'] ) ? sanitize_key( (string) $input['target'] ) : '', isset( $input['brand_id'] ) ? absint( $input['brand_id'] ) : 0, isset( $input['query_id'] ) ? absint( $input['query_id'] ) : 0, isset( $input['data'] ) && is_array( $input['data'] ) ? $input['data'] : array() ); if ( is_wp_error( $result ) ) { return $result; } $result['message'] = 'generate-queries' === $result['target'] ? sprintf( /* translators: %d: brand id */ __( 'Generated new baseline queries for AI Visibility brand %d. Credits were consumed.', 'acrossai-abilities-manager' ), $result['brand_id'] ) : sprintf( /* translators: 1: target name, 2: brand id */ __( 'Updated the AI Visibility %1$s for brand %2$d.', 'acrossai-abilities-manager' ), $result['target'], $result['brand_id'] ); return $result; } }