<?php

declare(strict_types=1);

namespace Maestro\Core\Support;

/**
 * Single source of truth for host scaffolding paths (managed vs custom zones).
 */
final class HostStubManifest
{
    public const MANAGED_BANNER = '@maestro-core-managed';

    /** @var array<string, string> stub path under stubs/ => path relative to project root */
    public const MANAGED_STUBS = [
        'vite.config.js' => 'vite.config.js',
        'tailwind.config.js' => 'tailwind.config.js',
        'routes/public.php' => 'routes/public.php',
        'routes/web.php' => 'routes/web.php',
        'app/Models/User.php' => 'app/Models/User.php',
        'database/seeders/DatabaseSeeder.php' => 'database/seeders/DatabaseSeeder.php',
        'resources/css/app.css' => 'resources/css/app.css',
        'resources/js/app.js' => 'resources/js/app.js',
        'resources/js/public-home.js' => 'resources/js/public-home.js',
        'resources/js/pages/Dashboard.vue' => 'resources/js/pages/Dashboard.vue',
        'resources/views/spa.blade.php' => 'resources/views/spa.blade.php',
    ];

    /** Published once; never overwritten by --force (except cursor rules via --refresh-cursor-rules). */
    public const CUSTOM_STUBS = [
        'database/seeders/CustomDatabaseSeeder.php' => 'database/seeders/CustomDatabaseSeeder.php',
        'app/Providers/CustomServiceProvider.php' => 'app/Providers/CustomServiceProvider.php',
        'config/custom.php' => 'config/custom.php',
        'resources/js/maestro/boot.js' => 'resources/js/maestro/boot.js',
        'resources/js/maestro/bootPublicHome.js' => 'resources/js/maestro/bootPublicHome.js',
        'resources/js/maestro/publicHome.vue' => 'resources/js/maestro/publicHome.vue',
        'resources/js/modules/custom/routes.js' => 'resources/js/modules/custom/routes.js',
        '.cursor/rules/maestro-host-custom-code.mdc' => '.cursor/rules/maestro-host-custom-code.mdc',
        '.cursor/rules/maestro-core-vs-custom.mdc' => '.cursor/rules/maestro-core-vs-custom.mdc',
        'AGENTS.md' => 'AGENTS.md',
        'README.md' => 'README.md',
        'scripts/check-no-maestro-link.sh' => 'scripts/check-no-maestro-link.sh',
        '.github/workflows/maestro-host-ci.yml' => '.github/workflows/maestro-host-ci.yml',
    ];

    /** @var array<string, string> */
    public const CURSOR_RULE_STUBS = [
        '.cursor/rules/maestro-host-custom-code.mdc' => '.cursor/rules/maestro-host-custom-code.mdc',
        '.cursor/rules/maestro-core-vs-custom.mdc' => '.cursor/rules/maestro-core-vs-custom.mdc',
    ];

    /** @var list<string> */
    public const HOST_CORE_FORK_FILES = [
        'resources/js/maestro/MaestroAppearanceSettingsPanel.vue',
        'resources/js/maestro/OrganizationProfileView.vue',
        'resources/js/maestro/UsersView.vue',
        'resources/js/maestro/theme.js',
        'resources/js/maestro/themeBootstrap.js',
        'resources/js/maestro/persistAppearance.js',
    ];

    /**
     * Relative paths under app/ that are allowed outside app/Custom/Features/.
     *
     * @var list<string>
     */
    public const HOST_BUSINESS_PHP_ALLOWLIST = [
        'Models/User.php',
        'Providers/AppServiceProvider.php',
        'Providers/CustomServiceProvider.php',
        'Http/Controllers/Controller.php',
    ];

    /** @var list<string> */
    public const BOOT_JS_ALLOWED_REMOVE_ROUTES = [
        'dashboard',
    ];

    public const LINK_STATE_FILE = '.maestro-link.json';

    public const COMPOSER_PATH_REPO_KEY = 'maestro-local-path';

    /**
     * Managed stubs auto-synced after composer update when the package stub is newer.
     *
     * @return array<string, string>
     */
    public static function autoSyncStubs(): array
    {
        return [
            'vite.config.js' => 'vite.config.js',
            'resources/css/app.css' => 'resources/css/app.css',
            'resources/js/app.js' => 'resources/js/app.js',
            'resources/js/public-home.js' => 'resources/js/public-home.js',
        ];
    }

    /**
     * @return list<string> Lines to ensure exist in host .gitignore
     */
    public static function gitignoreEntries(): array
    {
        return [
            '.maestro-link.json',
            '.cursor/settings.json',
        ];
    }
}
