#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"

if [[ ! -f ".env" ]]; then
  echo "ERROR: .env is missing in $ROOT_DIR"
  exit 1
fi

: "${QA_LINER_EMAIL:=liner2@lineup.fr}"
: "${QA_LINER_PASSWORD:=Lineup12j}"
: "${QA_LINER_NAME:=Liner Demo 2}"
: "${QA_LINER_PHONE:=+33600000003}"
: "${QA_LINER_IBAN:=FR7630006000011234567890189}"
: "${QA_LINER_BIC:=AGRIFRPP}"
: "${QA_LINER_DOCUMENT_NUMBER:=LNR-DEMO-002}"
: "${QA_LINER_DOCUMENT_URL:=https://example.com/kyc/liner2-cni.jpg}"

echo "== Setup QA liner2 =="
echo "Root: $ROOT_DIR"
echo "Email: $QA_LINER_EMAIL"
echo "Phone: $QA_LINER_PHONE"

env \
  QA_LINER_EMAIL="$QA_LINER_EMAIL" \
  QA_LINER_PASSWORD="$QA_LINER_PASSWORD" \
  QA_LINER_NAME="$QA_LINER_NAME" \
  QA_LINER_PHONE="$QA_LINER_PHONE" \
  QA_LINER_IBAN="$QA_LINER_IBAN" \
  QA_LINER_BIC="$QA_LINER_BIC" \
  QA_LINER_DOCUMENT_NUMBER="$QA_LINER_DOCUMENT_NUMBER" \
  QA_LINER_DOCUMENT_URL="$QA_LINER_DOCUMENT_URL" \
  php artisan db:seed --class=QaSecondLinerSeeder --force

echo
echo "QA liner ready. Credentials:"
echo "  login:    $QA_LINER_EMAIL"
echo "  password: $QA_LINER_PASSWORD"
