#!/usr/bin/env bash
# Deploy this base theme to any Shopify store as a NEW UNPUBLISHED theme.
#
#   ./deploy.sh mystore.myshopify.com            # unpublished copy
#   ./deploy.sh mystore.myshopify.com "My Theme" # with a custom name
#
# Never publishes and never touches a live theme. Publishing stays a
# deliberate click in the admin.
set -euo pipefail

STORE="${1:-}"
NAME="${2:-Aurelia $(date +%Y-%m-%d)}"

if [[ -z "$STORE" ]]; then
  echo "usage: ./deploy.sh <store>.myshopify.com [theme name]" >&2
  exit 1
fi

cd "$(dirname "$0")"

echo "==> Auditing before push"
python3 audit.py . | tail -3
if ! python3 audit.py . | grep -q "TOTAL ISSUES: 0"; then
  echo "!! Audit found issues. Fix them first, or re-run with SKIP_AUDIT=1" >&2
  [[ "${SKIP_AUDIT:-}" == "1" ]] || exit 1
fi

echo
echo "==> Pushing to $STORE as \"$NAME\" (unpublished)"
# NOTE: do not pipe this to grep. The success banner prints alongside
# errors, so filtering to "success" hides real schema failures.
shopify theme push --store "$STORE" --unpublished --theme "$NAME"

cat <<EOF

==> Per-store setup (do these once in the new store)

  1. snippets/store-schema.liquid
     Fill the assigns at the top: gsc_verification, biz_name, address,
     telephone, social_urls. They are blank by default so this theme does
     NOT carry another store's identity into a new one.

  2. Theme settings -> Colors
     Dawn ships neutral schemes. Set brand colours before publishing.

  3. Upload real images
     Sections fall back to picsum.photos placeholders via their
     "Image URL" field. Pick a real image and it wins automatically.

  4. Demo templates
     page.demo-{reformation,houseofcb,anthropologie,freepeople,urban,parke}
     Create a Page and choose one from the template dropdown to preview a
     full layout. Delete the ones you do not want.

  5. Preview, then publish from the admin when you are happy.
EOF
