<?php

namespace Database\Seeders;

use App\Models\Language;
use App\Models\TranslationKey;
use App\Models\Translation;
use App\Models\Company;
use Illuminate\Database\Seeder;

class SuppliersSidebarHindiTranslationsSeeder extends Seeder
{
    public function run(): void
    {
        $hindiLanguage = Language::where('code', 'hi')->first();
        if (!$hindiLanguage) {
            echo "Hindi language not found\n";
            return;
        }

        $companies = Company::all();
        if ($companies->isEmpty()) {
            echo "No companies found\n";
            return;
        }

        $translations = [
            'Suppliers System' => 'आपूर्तिकर्ता प्रणाली',
            'Suppliers List' => 'आपूर्तिकर्ता सूची',
            'Add New Supplier' => 'नया आपूर्तिकर्ता जोड़ें',
            'Supplier Contracts' => 'आपूर्तिकर्ता अनुबंध',
            'Add New Contract' => 'नया अनुबंध जोड़ें',
            'Supplier Invoices' => 'आपूर्तिकर्ता चालान',
            'Add New Invoice' => 'नया चालान जोड़ें',
            'Supplier Payments' => 'आपूर्तिकर्ता भुगतान',
            'Add New Payment' => 'नया भुगतान जोड़ें',
            'Supplier Reports' => 'आपूर्तिकर्ता रिपोर्ट',
        ];

        foreach ($translations as $englishKey => $hindiValue) {
            $translationKey = TranslationKey::updateOrCreate(
                ['key' => $englishKey],
                [
                    'group' => 'sidebar',
                    'context' => 'navigation',
                    'description' => 'Suppliers sidebar translations',
                ]
            );

            foreach ($companies as $company) {
                Translation::updateOrCreate(
                    [
                        'translation_key_id' => $translationKey->id,
                        'language_id' => $hindiLanguage->id,
                        'company_id' => $company->id,
                    ],
                    [
                        'value' => $hindiValue,
                        'status' => 'published',
                    ]
                );
            }
        }

        echo "\n✅ Hindi translations for Suppliers added successfully!\n";
    }
}
