#!/bin/bash

MEDUSA_ORDER_ID="order_01K1TQQHZGPXKDHAH81TDSNGXR"

# HOSTNAME="https://test.medreport.ee"
# JOBS_API_TOKEN="fd26ec26-70ed-11f0-9e95-431ac3b15a84"

HOSTNAME="http://localhost:3000"
JOBS_API_TOKEN=73ce073c-6dd4-11f0-8e75-8fee89786197

function send_medipost_test_response() {
  curl -X POST "$HOSTNAME/api/order/medipost-test-response" \
    --header "x-jobs-api-key: $JOBS_API_TOKEN" \
    --header 'Content-Type: application/json' \
    --data '{ "medusaOrderId": "'$MEDUSA_ORDER_ID'", "maxItems": 2 }'
}

function sync_analysis_results() {
  curl -X POST "$HOSTNAME/api/job/sync-analysis-results" \
    --header "x-jobs-api-key: $JOBS_API_TOKEN"
}

function sync_analysis_groups() {
  curl -X POST "$HOSTNAME/api/job/sync-analysis-groups" \
    --header "x-jobs-api-key: $JOBS_API_TOKEN"
}

function sync_analysis_groups_store() {
  curl -X POST "$HOSTNAME/api/job/sync-analysis-groups-store" \
    --header "x-jobs-api-key: $JOBS_API_TOKEN"
}

# Requirements

# 1. Sync analysis groups from Medipost to B2B
sync_analysis_groups

# 2. Optional - sync all Medipost analysis groups from B2B to Medusa (or add manually)
#sync_analysis_groups_store

# 3. Set up products configurations in Medusa so B2B "Telli analüüs" page shows the product and you can do payment flow

# 4. After payment is done, run `send_medipost_test_response` to send the fake test results to Medipost
# send_medipost_test_response

# 5. Run `sync_analysis_results` to sync the all new Medipost results to B2B
# sync_analysis_results
