---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_trained_model:
      model_id: "a-perfect-regression-model"
      body: "{\n  \"description\": \"empty model for tests\",\n  \"tags\": [\"regression\"\
        , \"tag1\"],\n  \"input\": {\"field_names\": [\"field1\", \"field2\"]},\n\
        \  \"inference_config\": { \"regression\": {\"results_field\": \"my_regression\"\
        }},\n  \"definition\": {\n     \"preprocessors\": [],\n     \"trained_model\"\
        : {\n        \"tree\": {\n           \"feature_names\": [\"field1\", \"field2\"\
        ],\n           \"tree_structure\": [\n              {\"node_index\": 0, \"\
        leaf_value\": 42}\n           ],\n           \"target_type\": \"regression\"\
        \n        }\n     }\n  }\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test create processor with missing mandatory fields:
- do:
    catch: "/\\[model_id\\] required property is missing/"
    ingest.put_pipeline:
      id: "regression-model-pipeline"
      body: "{\n  \"processors\": [\n    {\n      \"inference\" : {\n        \"inference_config\"\
        : {\"regression\": {}},\n        \"target_field\": \"regression_field\",\n\
        \        \"field_map\": {}\n      }\n    }\n  ]\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test simulate:
- skip:
    awaits_fix: "https://github.com/elastic/elasticsearch/issues/107815"
- do:
    ingest.simulate:
      body: "{\n  \"pipeline\": {\n  \"processors\": [\n    {\n      \"inference\"\
        \ : {\n        \"model_id\" : \"a-perfect-regression-model\",\n        \"\
        target_field\": \"regression_field\",\n        \"field_map\": {}\n      }\n\
        \    }\n  ]},\n  \"docs\": [{\"_source\": {\"field1\": 1, \"field2\": 2}}]\n\
        }\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    docs.0.doc._source.regression_field.my_regression: 42.0
- do:
    ingest.simulate:
      body: "{\n  \"pipeline\": {\n  \"processors\": [\n    {\n      \"inference\"\
        \ : {\n        \"model_id\" : \"a-perfect-regression-model\",\n        \"\
        inference_config\": {\"regression\": {\"results_field\": \"value\"}},\n  \
        \      \"target_field\": \"regression_field\"\n      }\n    }\n  ]},\n  \"\
        docs\": [{\"_source\": {\"field1\": 1, \"field2\": 2}}]\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    docs.0.doc._source.regression_field.value: 42.0
