# yaml-language-server: $schema=./schemas/collection.json
# Note: This file is meant primarily for development and testing of Slumber. It
# is not intended as documentation. While it may be a helpful example, canonical
# documentation is at: https://slumber.lucaspickering.me/

.base_profile_data:
  username: xX{{ command(['whoami']) | trim() | sensitive() }}Xx
  fish_id: "{{ response('list_fish', trigger='no_history')
    | jq('[.[] | { label: .name, value: .id }]')
    | select(message='Fish ID') }}"
  stream_compound: "command: {{ command(['echo', 'test']) }}\nfile: {{ file('Cargo.toml') }}"
  large_body_command: "head -c {{ prompt(message='Bytes', default=500000) }} < /dev/urandom | base64"

profiles:
  prd:
    name: Production
    default: true
    data:
      $ref: "#/.base_profile_data"
      host: https://shoal.lucaspickering.me
  local:
    name: Local
    data:
      $ref: "#/.base_profile_data"
      host: http://localhost:3000
  init-fails:
    name: Request Init Fails
    data:
      $ref: "#/.base_profile_data"
  request-fails:
    name: Request Fails
    data:
      $ref: "#/.base_profile_data"
      host: http://localhost:5000

.base_request:
  headers:
    Accept: application/json
.authenticated:
  $ref: "#/.base_request"
  authentication:
    type: bearer
    token: "{{ response('new_session', trigger='1h') | jsonpath('$.id') }}"

requests:
  new_session:
    $ref: "#/.base_request"
    name: New Session
    method: POST
    url: "{{ host }}/login"

  fish:
    name: Fish
    requests:
      list_fish:
        $ref: "#/.authenticated"
        name: List Fish
        method: GET
        url: "{{ host }}/fish"
        query:
          foo: bar

      get_fish:
        $ref: "#/.authenticated"
        name: Get Fish
        method: GET
        url: "{{ host }}/fish/{{ fish_id }}"
        query:
          select: "{{ select(
            ['foo', 'bar', 'baz', 'a really really really really long option', username],
            message='Select a value'
            ) }}"

      create_fish:
        $ref: "#/.authenticated"
        name: Create Fish
        method: POST
        url: "{{ host }}/fish"
        body:
          type: json
          data:
            {
              "name": "{{ prompt(message='Name', default='Fishy') }}",
              "species": "{{ select(['Sunfish', 'baby fuckin wheel'], message='Species') }}",
              "age": "{{ prompt(message='Age', default=3) | integer() }}",
              "weight_kg": "{{ prompt(message='Weight (kg)', default='1000.5') | float() }}",
            }

      modify_fish:
        $ref: "#/.authenticated"
        name: Modify Fish
        method: PATCH
        url: "{{ host }}/fish/{{ fish_id }}"
        body:
          type: json
          data:
            {
              "age": "{{ prompt(message='Age', default=3) | integer() }}",
              "weight_kg": "{{ prompt(message='Weight (kg)', default='1.5') | float() }}",
            }

      delete_fish:
        $ref: "#/.authenticated"
        name: Delete Fish
        method: DELETE
        url: "{{ host }}/fish/{{ fish_id }}"

  authentication:
    name: Authentication
    requests:
      basic_auth:
        $ref: "#/.base_request"
        method: POST
        url: "{{ host }}/anything/login"
        persist: false
        authentication:
          type: basic
          username: "{{ username }}"
          password: "{{ prompt(message='Password') }}"
        query:
          sudo: yes_please
          fast: [no_thanks, actually_maybe]
        headers:
          Accept: application/json

      bearer_auth:
        $ref: "#/.base_request"
        method: POST
        url: "{{ host }}/anything/login"
        persist: false
        authentication:
          type: bearer
          token: auth_token
        query:
          sudo: yes_please
          fast: [no_thanks, actually_maybe]
        headers:
          Accept: application/json

  bodies:
    name: Misc Bodies
    requests:
      stream_file:
        $ref: "#/.base_request"
        name: Stream File
        method: POST
        url: "{{ host }}/anything"
        body:
          type: stream
          data: "{{ file('Cargo.toml') }}"

      stream_command:
        $ref: "#/.base_request"
        name: Stream Command
        method: POST
        url: "{{ host }}/anything"
        body:
          type: stream
          data: "{{ command(['cat', 'Cargo.toml']) }}"

      stream_compound:
        $ref: "#/.base_request"
        name: Stream Compound
        method: POST
        url: "{{ host }}/anything"
        body:
          type: stream
          data: "{{ stream_compound }}"

      form_urlencoded:
        $ref: "#/.base_request"
        method: POST
        url: "{{ host }}/anything"
        body:
          type: form_urlencoded
          data:
            username: "{{ username }}"
            password: "{{ prompt(message='Password', default='hunter2', sensitive=true) }}"

      form_multipart:
        $ref: "#/.base_request"
        method: POST
        url: "{{ host }}/anything"
        body:
          type: form_multipart
          data:
            image: "{{ prompt(message='Path', default='static/slumber.png') | file() }}"

      raw_json:
        $ref: "#/.base_request"
        name: Raw JSON
        method: POST
        url: "{{ host }}/anything"
        headers:
          Content-Type: application/json
        body: >
          {
            "location": "boston",
            "size": "HUGE"
          }

      large_body:
        $ref: "#/.base_request"
        name: Large Body
        method: POST
        url: "{{ host }}/anything"
        body: "{{ command(['sh', '-c', large_body_command]) }}"

  delay:
    $ref: "#/.base_request"
    name: Delay
    method: GET
    url: "{{ host }}/delay/5"

  redirect:
    $ref: "#/.base_request"
    name: Redirect
    method: GET
    url: "{{host}}/redirect-to?url={{host}}/get"
