#!/usr/bin/env bash
#
# Verifies the InfrastructureFutures domain folder matches the layout fixed in
# docs/build-guide.md Part 3. This is a local stand-in for the referenced
# house `ddd-lint.sh` (spec-laravel-ddd-backend) — that spec/script was not
# found anywhere on this machine, so this reimplements only the structural
# checks the build guide itself describes. Replace with the real house
# script if/when it turns up.
#
set -euo pipefail

REPO="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
DOMAIN="$REPO/app/Domain/InfrastructureFutures"
FAIL=0

require_dir() {
    if [ ! -d "$DOMAIN/$1" ]; then
        echo "MISSING: app/Domain/InfrastructureFutures/$1"
        FAIL=1
    fi
}

if [ ! -d "$DOMAIN" ]; then
    echo "MISSING: app/Domain/InfrastructureFutures"
    exit 1
fi

for dir in \
    Actions \
    DTOs \
    Enums \
    Http/Controllers \
    Http/Middleware \
    Http/Requests \
    Http/Resources \
    Models \
    Models/Concerns \
    Observers \
    Policies \
    Queries/Public \
    Queries/Internal \
    Services \
    Support \
    ValueObjects
do
    require_dir "$dir"
done

# House rule: plain Eloquent, direct access from Actions/Queries — no repository layer.
if [ -d "$DOMAIN/Repositories" ]; then
    echo "FORBIDDEN: app/Domain/InfrastructureFutures/Repositories — no repositories, per the house spec"
    FAIL=1
fi

if [ "$FAIL" -ne 0 ]; then
    echo "ddd-lint: FAILED"
    exit 1
fi

echo "ddd-lint: OK — $DOMAIN matches the fixed layout"
