# -----------------------------
# CONFIG
# -----------------------------
$env:APPWRITE_ENDPOINT = "https://appwrite.webklar.com/v1"
$env:APPWRITE_PROJECT_ID = "696533bd0003952a02d4"
$env:APPWRITE_API_KEY = "297b989f4f706df75aee7d768422021787228412c88d00d663a3dae462e09d74a8c18ae973f44c8693c1fc65c2cc0939e4887f44b08548234df464e9acaeee7392c1cf35711bc94b0aa33eec2d5dd3b0178acc3061a34dca13b23f5f94e0db4d0f80bc53fbb63f2ec3b2eb2372c1d5cfa17483e150cbfde8a7b82759334abb82"

# IDs
$env:DB_ID = "mail-sorter"
$env:DB_NAME = "Mail Sorter"
$env:TABLE_PRODUCTS = "products"
$env:TABLE_QUESTIONS = "questions"
$env:TABLE_SUBMISSIONS = "submissions"
$env:TABLE_ANSWERS = "answers"
$env:TABLE_ORDERS = "orders"

# Produkt
$env:PRODUCT_ID = "mail-sorter-product"
$env:PRODUCT_SLUG = "email-sorter"
$env:PRODUCT_TITLE = "E-Mail Sortierer"
$env:PRODUCT_PRICE_CENTS = "4900"
$env:PRODUCT_CURRENCY = "eur"

# -----------------------------
# RUN
# -----------------------------
if (-not (Test-Path ".\server")) {
    New-Item -ItemType Directory -Path ".\server" | Out-Null
}

Set-Location ".\server"

# Node deps
if (-not (Test-Path "package.json")) {
    npm init -y | Out-Null
    npm i node-appwrite | Out-Null
}

Write-Host "Creating bootstrap script..."

Write-Host "Running bootstrap script..."
node bootstrap-appwrite.mjs

if ($LASTEXITCODE -eq 0) {
    Write-Host "`nAll done. DB/Tables/Columns created and 13 questions seeded." -ForegroundColor Green
} else {
    Write-Host "`nError occurred during setup." -ForegroundColor Red
}
