#!/bin/bash

# This script creates 2 teams and 4 users with various roles.

source $FLEET_ENV_PATH

# Create teams
create_team_endpoint="api/v1/fleet/teams"

# Create Apples
data='{
  "name": "Apples"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_team_endpoint" -d "$data" --insecure

# Create Oranges
data='{
  "name": "Oranges"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_team_endpoint" -d "$data" --insecure

# Create users
create_user_endpoint="api/v1/fleet/users/admin"

# Create Anna
data='{
  "name": "Anna",
  "email": "anna@organization.com",
  "password": "user123#",
  "invited_by": 1,
  "global_role": "admin"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure

# Create Mary
data='{
  "name": "Mary",
  "email": "mary@organization.com",
  "password": "user123#",
  "invited_by": 1,
  "global_role": "maintainer"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure

# Create Oliver
data='{
  "name": "Oliver",
  "email": "oliver@organization.com",
  "password": "user123#",
  "invited_by": 1,
  "global_role": "observer"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure

# Create Marco
data='{
  "name": "Marco",
  "email": "marco@organization.com",
  "password": "user123#",
  "invited_by": 1,
  "global_role": null,
  "teams": [
    {
      "id": 1,
      "role": "observer"
    },
    {
      "id": 2,
      "role": "maintainer"
    }
  ]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure

# Create Toni
data='{
  "name": "Toni",
  "email": "toni@organization.com",
  "password": "user123#",
  "invited_by": 1,
  "global_role": null,
  "teams": [
    {
      "id": 1,
      "role": "observer"
    }
  ]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
