<?php

namespace Database\Seeders;

use App\Models\Currency;
use App\Models\Permission;
use Illuminate\Database\Seeder;

class ReferenceDataSeeder extends Seeder
{
    public function run(): void
    {
        foreach ([
            ['code' => 'KES', 'name' => 'Kenyan Shilling', 'symbol' => 'KSh', 'exchange_rate' => 1, 'is_base' => true, 'is_active' => true],
            ['code' => 'USD', 'name' => 'US Dollar', 'symbol' => '$', 'exchange_rate' => 129.5, 'is_base' => false, 'is_active' => true],
        ] as $currency) {
            Currency::query()->updateOrCreate(['code' => $currency['code']], $currency);
        }

        foreach ([
            ['name' => 'View Products', 'slug' => 'products.view', 'module' => 'inventory'],
            ['name' => 'Manage Products', 'slug' => 'products.manage', 'module' => 'inventory'],
            ['name' => 'View Stock', 'slug' => 'stock.view', 'module' => 'inventory'],
            ['name' => 'Adjust Stock', 'slug' => 'stock.adjust', 'module' => 'inventory'],
            ['name' => 'View Purchases', 'slug' => 'purchases.view', 'module' => 'purchases'],
            ['name' => 'Manage Purchases', 'slug' => 'purchases.manage', 'module' => 'purchases'],
            ['name' => 'Receive Purchases', 'slug' => 'purchases.receive', 'module' => 'purchases'],
            ['name' => 'View Customers', 'slug' => 'customers.view', 'module' => 'customers'],
            ['name' => 'Manage Customers', 'slug' => 'customers.manage', 'module' => 'customers'],
            ['name' => 'Manage Shifts', 'slug' => 'shifts.manage', 'module' => 'sales'],
            ['name' => 'View Orders', 'slug' => 'orders.view', 'module' => 'sales'],
            ['name' => 'Manage Orders', 'slug' => 'orders.manage', 'module' => 'sales'],
            ['name' => 'Manage Payments', 'slug' => 'payments.manage', 'module' => 'sales'],
            ['name' => 'View Returns', 'slug' => 'returns.view', 'module' => 'sales'],
            ['name' => 'Manage Returns', 'slug' => 'returns.manage', 'module' => 'sales'],
            ['name' => 'View Expenses', 'slug' => 'expenses.view', 'module' => 'expenses'],
            ['name' => 'Manage Expenses', 'slug' => 'expenses.manage', 'module' => 'expenses'],
            ['name' => 'Approve Expenses', 'slug' => 'expenses.approve', 'module' => 'expenses'],
            ['name' => 'View Reports', 'slug' => 'reports.view', 'module' => 'reports'],
            ['name' => 'Manage Settings', 'slug' => 'settings.manage', 'module' => 'settings'],
            ['name' => 'Manage Branches', 'slug' => 'branches.manage', 'module' => 'settings'],
        ] as $permission) {
            Permission::query()->updateOrCreate(['slug' => $permission['slug']], $permission);
        }
    }
}
