<?php

namespace Database\Seeders;

use App\Models\Category;
use App\Models\Currency;
use App\Models\Product;
use App\Models\Setting;
use App\Models\Translation;
use App\Models\Unit;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        User::updateOrCreate(['email' => 'admin@solar.af'], ['name' => 'System Administrator', 'role' => 'manager', 'password' => Hash::make('ChangeMe123!')]);
        foreach ([['AFN', 'Afghan Afghani', '؋', 1, true], ['USD', 'US Dollar', '$', 70, false], ['PKR', 'Pakistani Rupee', '₨', 0.25, false]] as [$code, $name, $symbol, $rate, $default]) Currency::updateOrCreate(['code' => $code], compact('name', 'symbol') + ['exchange_rate' => $rate, 'is_default' => $default, 'is_active' => true]);
        foreach ([['Piece', 'pc'], ['Meter', 'm'], ['Roll', 'roll'], ['Set', 'set'], ['Box', 'box'], ['Foot', 'ft']] as [$name, $shortName]) Unit::updateOrCreate(['short_name' => $shortName], ['name' => $name]);
        foreach ([['Solar Panels', 'fa-solar-panel'], ['Solar Pumps', 'fa-faucet-drip'], ['Inverters', 'fa-bolt'], ['Batteries', 'fa-car-battery'], ['Cables & Wires', 'fa-plug'], ['Pipes & Fittings', 'fa-pipe'], ['Accessories', 'fa-screwdriver-wrench']] as [$name, $icon]) Category::firstOrCreate(['name' => $name], ['icon' => $icon]);
        $panel = Category::where('name', 'Solar Panels')->first();
        Product::updateOrCreate(['sku' => 'PANEL-550W'], ['category_id' => $panel->id, 'name' => '550W Mono Solar Panel', 'unit' => 'pc', 'cost_price' => 5500, 'retail_price' => 6500, 'wholesale_price' => 6100, 'stock_quantity' => 20, 'low_stock_at' => 5]);
        foreach (['business_name' => 'Afghan Solar Solutions', 'business_address' => 'Kabul, Afghanistan', 'business_phone' => '+93', 'business_email' => '', 'tax_number' => '', 'invoice_footer' => 'Thank you for your business.', 'invoice_terms' => 'Goods once sold are returnable only according to company policy.', 'report_footer' => 'This report is generated from live business records.', 'invoice_size' => 'a4'] as $key => $value) Setting::updateOrCreate(['key' => $key], ['value' => $value, 'group' => 'general']);
        $words = ['Dashboard' => ['fa' => 'داشبورد', 'ps' => 'ډشبورډ'], 'Products' => ['fa' => 'محصولات', 'ps' => 'محصولات'], 'Customers' => ['fa' => 'مشتریان', 'ps' => 'پیرودونکي'], 'Suppliers' => ['fa' => 'تأمین‌کنندگان', 'ps' => 'عرضه کوونکي'], 'Purchases' => ['fa' => 'خریدها', 'ps' => 'پیرودنې'], 'New Sale' => ['fa' => 'فروش جدید', 'ps' => 'نوې خرڅلاو'], 'Invoices' => ['fa' => 'فاکتورها', 'ps' => 'بلونه'], 'Payments & Receipts' => ['fa' => 'پرداخت‌ها و دریافت‌ها', 'ps' => 'تادیات او ترلاسه کول'], 'Expenses' => ['fa' => 'مصارف', 'ps' => 'لګښتونه'], 'Reports' => ['fa' => 'گزارش‌ها', 'ps' => 'راپورونه'], 'Settings' => ['fa' => 'تنظیمات', 'ps' => 'امستنې'], 'Translations' => ['fa' => 'ترجمه‌ها', 'ps' => 'ژباړې'], 'Retail' => ['fa' => 'پرچون', 'ps' => 'پرچون'], 'Wholesale' => ['fa' => 'عمده', 'ps' => 'عمده'], 'Balance Due' => ['fa' => 'بدهی باقی‌مانده', 'ps' => 'پاتې بیلانس'], 'Receive from Customer' => ['fa' => 'دریافت از مشتری', 'ps' => 'له پېرودونکي ترلاسه کول'], 'Pay Supplier' => ['fa' => 'پرداخت به تأمین‌کننده', 'ps' => 'عرضه کوونکي ته پیسې ورکول']];
        foreach ($words as $key => $values) foreach ($values as $locale => $value) Translation::updateOrCreate(['locale' => $locale, 'key' => $key], ['value' => $value]);
        $extraWords = [
            'Configuration' => ['fa' => 'تنظیمات', 'ps' => 'امستنې'],
            'Business Settings' => ['fa' => 'تنظیمات تجارت', 'ps' => 'د سوداګرۍ امستنې'],
            'Categories' => ['fa' => 'دسته بندی ها', 'ps' => 'کټګورۍ'],
            'Units' => ['fa' => 'واحدها', 'ps' => 'واحدونه'],
            'Translation Manager' => ['fa' => 'مدیریت ترجمه', 'ps' => 'د ژباړې مدیر'],
            'Business Reports' => ['fa' => 'گزارش های تجارتی', 'ps' => 'سوداګریز راپورونه'],
            'Report Center' => ['fa' => 'مرکز گزارش ها', 'ps' => 'د راپورونو مرکز'],
            'Customer Balances' => ['fa' => 'بیلانس مشتریان', 'ps' => 'د پېرودونکو بیلانسونه'],
            'Supplier Balances' => ['fa' => 'بیلانس تامین کنندگان', 'ps' => 'د عرضه کوونکو بیلانسونه'],
            'Invoice Terms' => ['fa' => 'شرایط فاکتور', 'ps' => 'د بل شرایط'],
            'Report Footer' => ['fa' => 'پایین نویس گزارش', 'ps' => 'د راپور پای لیک'],
            'Tax / Registration No.' => ['fa' => 'شماره مالیه / ثبت', 'ps' => 'د مالیې / ثبت شمېره'],
            'Localization Progress' => ['fa' => 'پیشرفت محلی سازی', 'ps' => 'د ځایي کولو پرمختګ'],
            'Missing Translation Keys' => ['fa' => 'کلیدهای ترجمه نشده', 'ps' => 'ناژباړل شوي کلیدونه'],
            'Saved Translations' => ['fa' => 'ترجمه های ذخیره شده', 'ps' => 'ساتل شوې ژباړې'],
            'Wizard Forms' => ['fa' => 'فورم های راهنما', 'ps' => 'لارښود فورمونه'],
            'New Sale Wizard' => ['fa' => 'راهنمای فروش جدید', 'ps' => 'د نوي پلور لارښود'],
            'New Purchase Wizard' => ['fa' => 'راهنمای خرید جدید', 'ps' => 'د نوي پېرود لارښود'],
            'Stock Wizard' => ['fa' => 'راهنمای گدام', 'ps' => 'د سټاک لارښود'],
            'Payment Wizard' => ['fa' => 'راهنمای پرداخت', 'ps' => 'د تادیې لارښود'],
            'Received Wizard' => ['fa' => 'راهنمای دریافت', 'ps' => 'د ترلاسه کولو لارښود'],
            'Backup & Restore' => ['fa' => 'پشتیبان و بازگردانی', 'ps' => 'بیک اپ او بېرته راوستل'],
            'Create Backup' => ['fa' => 'ایجاد پشتیبان', 'ps' => 'بیک اپ جوړول'],
            'Restore Backup' => ['fa' => 'بازگردانی پشتیبان', 'ps' => 'بیک اپ بېرته راوستل'],
            'Download Backup' => ['fa' => 'دانلود پشتیبان', 'ps' => 'بیک اپ ښکته کول'],
            'Desktop Launcher' => ['fa' => 'اجرای دسکتاپ', 'ps' => 'ډېسکټاپ چلوونکی'],
            'Run as Desktop App' => ['fa' => 'اجرای برنامه دسکتاپ', 'ps' => 'د ډېسکټاپ اپ په ډول چلول'],
            'System' => ['fa' => 'سیستم', 'ps' => 'سیستم'],
            'Chart of Accounts' => ['fa' => 'چارت حسابات', 'ps' => 'د حسابونو چارت'],
            'Account Name' => ['fa' => 'نام حساب', 'ps' => 'د حساب نوم'],
            'Group' => ['fa' => 'گروه', 'ps' => 'ډله'],
            'Debit' => ['fa' => 'بدهکار', 'ps' => 'ډېبټ'],
            'Credit' => ['fa' => 'بستانکار', 'ps' => 'کرېډټ'],
            'As of' => ['fa' => 'تا تاریخ', 'ps' => 'تر نېټې'],
            'Printed' => ['fa' => 'چاپ شده', 'ps' => 'چاپ شوی'],
            'Total Assets' => ['fa' => 'مجموع دارایی ها', 'ps' => 'ټولې شتمنۍ'],
            'Liabilities & Equity' => ['fa' => 'بدهی ها و سرمایه', 'ps' => 'پورونه او سرمایه'],
            'Owner Equity' => ['fa' => 'سرمایه مالک', 'ps' => 'د مالک سرمایه'],
        ];
        foreach ($extraWords as $key => $values) foreach ($values as $locale => $value) Translation::updateOrCreate(['locale' => $locale, 'key' => $key], ['value' => $value]);
    }
}
