---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    ml.put_job:
      job_id: "forecast-job"
      body: "{\n  \"description\":\"A forecast job\",\n  \"analysis_config\" : {\n\
        \      \"detectors\" :[{\"function\":\"metric\",\"field_name\":\"responsetime\"\
        ,\"by_field_name\":\"airline\"}]\n  },\n  \"data_description\" : {\n     \
        \ \"format\":\"xcontent\"\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 forecast unknown job:
- skip:
    reason: "https://github.com/elastic/elasticsearch/issues/34747"
    cluster_features:
    - "gte_v6.5.0"
- do:
    catch: "missing"
    ml.forecast:
      job_id: "non-existing-job"
    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 forecast on closed job:
- do:
    catch: "/status_exception/"
    ml.forecast:
      job_id: "forecast-job"
    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 forecast given duration is zero:
- do:
    catch: "/\\[duration\\] must be positive[:] \\[0s\\]/"
    ml.forecast:
      job_id: "forecast-job"
      duration: "0s"
    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 forecast given duration is negative:
- do:
    catch: "/\\[duration\\] must be positive[:] \\[-1\\]/"
    ml.forecast:
      job_id: "forecast-job"
      duration: "-1"
    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 forecast given duration is too large:
- do:
    catch: "/\\[duration\\] must be 3650d or less[:] \\[3651d\\]/"
    ml.forecast:
      job_id: "forecast-job"
      duration: "3651d"
    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 forecast given expires_in is negative:
- do:
    catch: "/\\[expires_in\\] must be non-negative[:] \\[-1\\]/"
    ml.forecast:
      job_id: "forecast-job"
      expires_in: "-1"
    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 forecast given max_model_memory is too large:
- do:
    catch: "/\\[max_model_memory\\] must be less than 500mb/"
    ml.forecast:
      job_id: "forecast-job"
      max_model_memory: "1000mb"
    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"
