<?php

namespace Database\Seeders;

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

class PermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $permissions = [
            // Transactions
            ['name' => 'view_transactions', 'display_name' => 'View Transactions', 'description' => 'View all transactions', 'category' => 'transactions'],
            ['name' => 'create_transactions', 'display_name' => 'Create Transactions', 'description' => 'Create new transactions', 'category' => 'transactions'],
            ['name' => 'edit_transactions', 'display_name' => 'Edit Transactions', 'description' => 'Edit existing transactions', 'category' => 'transactions'],
            ['name' => 'delete_transactions', 'display_name' => 'Delete Transactions', 'description' => 'Delete transactions', 'category' => 'transactions'],

            // Bank Accounts
            ['name' => 'view_bank_accounts', 'display_name' => 'View Bank Accounts', 'description' => 'View all bank accounts', 'category' => 'bank_accounts'],
            ['name' => 'create_bank_accounts', 'display_name' => 'Create Bank Accounts', 'description' => 'Create new bank accounts', 'category' => 'bank_accounts'],
            ['name' => 'edit_bank_accounts', 'display_name' => 'Edit Bank Accounts', 'description' => 'Edit bank accounts', 'category' => 'bank_accounts'],
            ['name' => 'delete_bank_accounts', 'display_name' => 'Delete Bank Accounts', 'description' => 'Delete bank accounts', 'category' => 'bank_accounts'],

            // Digital Payments
            ['name' => 'view_digital_payments', 'display_name' => 'View Digital Payments', 'description' => 'View all digital payments', 'category' => 'digital_payments'],
            ['name' => 'create_digital_payments', 'display_name' => 'Create Digital Payments', 'description' => 'Create new digital payments', 'category' => 'digital_payments'],
            ['name' => 'edit_digital_payments', 'display_name' => 'Edit Digital Payments', 'description' => 'Edit digital payments', 'category' => 'digital_payments'],
            ['name' => 'delete_digital_payments', 'display_name' => 'Delete Digital Payments', 'description' => 'Delete digital payments', 'category' => 'digital_payments'],

            // Products
            ['name' => 'view_products', 'display_name' => 'View Products', 'description' => 'View all products', 'category' => 'products'],
            ['name' => 'create_products', 'display_name' => 'Create Products', 'description' => 'Create new products', 'category' => 'products'],
            ['name' => 'edit_products', 'display_name' => 'Edit Products', 'description' => 'Edit products', 'category' => 'products'],
            ['name' => 'delete_products', 'display_name' => 'Delete Products', 'description' => 'Delete products', 'category' => 'products'],

            // Expenses
            ['name' => 'view_expenses', 'display_name' => 'View Expenses', 'description' => 'View all expenses', 'category' => 'expenses'],
            ['name' => 'create_expenses', 'display_name' => 'Create Expenses', 'description' => 'Create new expenses', 'category' => 'expenses'],
            ['name' => 'edit_expenses', 'display_name' => 'Edit Expenses', 'description' => 'Edit expenses', 'category' => 'expenses'],
            ['name' => 'delete_expenses', 'display_name' => 'Delete Expenses', 'description' => 'Delete expenses', 'category' => 'expenses'],

            // Invoices
            ['name' => 'view_invoices', 'display_name' => 'View Invoices', 'description' => 'View all invoices', 'category' => 'invoices'],
            ['name' => 'create_invoices', 'display_name' => 'Create Invoices', 'description' => 'Create new invoices', 'category' => 'invoices'],
            ['name' => 'edit_invoices', 'display_name' => 'Edit Invoices', 'description' => 'Edit invoices', 'category' => 'invoices'],
            ['name' => 'delete_invoices', 'display_name' => 'Delete Invoices', 'description' => 'Delete invoices', 'category' => 'invoices'],

            // Reports
            ['name' => 'view_reports', 'display_name' => 'View Reports', 'description' => 'View all reports', 'category' => 'reports'],
            ['name' => 'view_balance_sheet', 'display_name' => 'View Balance Sheet', 'description' => 'View balance sheet report', 'category' => 'reports'],
            ['name' => 'view_profit_loss', 'display_name' => 'View Profit & Loss', 'description' => 'View profit and loss report', 'category' => 'reports'],

            // Customer Management
            ['name' => 'view_customers', 'display_name' => 'View Customers', 'description' => 'View all customers', 'category' => 'customers'],
            ['name' => 'create_customers', 'display_name' => 'Create Customers', 'description' => 'Create new customers', 'category' => 'customers'],
            ['name' => 'edit_customers', 'display_name' => 'Edit Customers', 'description' => 'Edit customer information', 'category' => 'customers'],

            // Admin Management
            ['name' => 'manage_admins', 'display_name' => 'Manage Admins', 'description' => 'Manage admin users and permissions', 'category' => 'admin'],
            ['name' => 'view_admin_dashboard', 'display_name' => 'View Admin Dashboard', 'description' => 'Access admin dashboard', 'category' => 'admin'],

            // Activity Logs & Audit Trail
            ['name' => 'view_activity_logs', 'display_name' => 'View Activity Logs', 'description' => 'View admin activity history and audit trail', 'category' => 'audit'],
            ['name' => 'view_transaction_history', 'display_name' => 'View Transaction History', 'description' => 'View detailed transaction activity logs', 'category' => 'audit'],
            ['name' => 'export_activity_logs', 'display_name' => 'Export Activity Logs', 'description' => 'Export activity logs to CSV', 'category' => 'audit'],

            // Super Admin Dashboard
            ['name' => 'manage_super_admin', 'display_name' => 'Super Admin Panel', 'description' => 'Access super admin panel', 'category' => 'super_admin'],
        ];

        foreach ($permissions as $permission) {
            Permission::firstOrCreate(
                ['name' => $permission['name']],
                $permission
            );
        }
    }
}
