<?php

namespace Database\Seeders;

use App\Models\ArchiveEntity;
use Illuminate\Database\Seeder;

class ArchiveEntitySeeder extends Seeder
{
    /**
     * Seed archive focus entities and their selectable related tables.
     */
    public function run(): void
    {
        $entities = [
            [
                'focus' => 'contracts',
                'name' => 'Contracts',
                'description' => 'Contracts and their financial / activity related records.',
                'related' => [
                    // Direct related tables
                    'accounts',
                    'activities',
                    'documents', // polymorphic (contract documents only when used as focus)
                    // Chained relations (dot notation) – resolve via contract -> account -> payments/bookings
                    'account.payments',
                    'account.bookings',
                ],
            ],
            [
                'focus' => 'client_cases',
                'name' => 'Client Cases',
                'description' => 'Client cases and subordinate contractual / financial records.',
                'related' => [
                    'contracts',          // direct contracts under case
                    'contracts.account',  // via contracts (hasOne account)
                    'activities',         // case level activities (and possibly contract-linked)
                    'documents',          // case level documents
                    // Chained relations:
                    'contracts.account.payments',   // contracts -> account -> payments
                    'contracts.account.bookings',   // contracts -> account -> bookings
                    'contracts.documents', // contracts -> documents (polymorphic)
                ],
            ],
        ];

        foreach ($entities as $data) {
            ArchiveEntity::query()->updateOrCreate(
                ['focus' => $data['focus']],
                [
                    'name' => $data['name'],
                    'description' => $data['description'],
                    'related' => $data['related'],
                    'enabled' => true,
                ]
            );
        }
    }
}
