### Run Typesense via Docker ########################################

export TYPESENSE_API_KEY=xyz
export TYPESENSE_URL="http://localhost:8108"

mkdir "$(pwd)"/typesense-data

docker run -p 8108:8108 -v"$(pwd)"/typesense-data:/data typesense/typesense:28.0 \
  --data-dir /data \
  --api-key=$TYPESENSE_API_KEY \
  --enable-cors

### Reproduction Steps ###############################################
#export TYPESENSE_API_KEY=xyz

curl "$TYPESENSE_URL/debug" \
  -L \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"

curl "$TYPESENSE_URL/collections" \
  -X POST \
  -L \
  -H "Content-Type: application/json" \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
  -d '{
         "name": "attributes_test",
  "enable_nested_fields": true,
         "fields": [
           {"name": "name", "type": "string" },
{
      "name": "attributes",
      "type": "object[]",
      "optional": true
    },
    {
      "name": "attributes.trait_type",
      "type": "string[]",
      "facet": true
    },
    {
      "name": "attributes.string_value",
      "type": "string[]",
      "facet": true,
      "optional": true
    }
         ]
       }'

curl "$TYPEENSE_URL/collections/attributes_test/documents/import?action=create" \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
  -H "Content-Type: text/plain" \
  -L \
  -X POST \
  -d '{"id": "1","nme": "Test1", "attributes": [ { "trait_type": "Tier", "string_value": "Common" }, { "trait_type": "Full Name", "string_value": "Bob" }]}
  {"id": "2","nme": "Test2", "attributes": [ { "trait_type": "Tier", "string_value": "Common" }, { "trait_type": "Full Name", "string_value": "Terry" }]}
  {"id": "3","nme": "Test3", "attributes": [ { "trait_type": "Tier", "string_value": "Uncommon" }, { "trait_type": "Full Name", "string_value": "John" }]}'

curl "$TYPESENSE_URL/multi_search" \
  -X POST \
  -L \
  -H "Content-Type: application/json" \
  -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
  -d '{
          "searches": [
            {
              "collection": "attributes_test",
              "q": "",
              "query_by": "name",
              "facet_by": "attributes.string_value",
              "facet_return_parent" : "attributes.string_value",
            }
          ]
        }'

### Documentation ######################################################################################
# Visit the API reference section: https://typesense.org/docs/28.0/api/collections.html
# Click on the "Shell" tab under each API resource's docs, to get shell commands for other API endpoints
