<?php

namespace Database\Seeders;

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

class PermissionSeeder extends Seeder
{
    public function run(): void
    {
        $modules = [
            'branches' => ['view', 'create', 'update', 'delete'],
            'users' => ['view', 'create', 'update', 'delete'],
            'roles' => ['view', 'create', 'update', 'delete', 'assign'],
            'permissions' => ['view', 'assign'],
            'categories' => ['view', 'create', 'update', 'delete'],
            'products' => ['view', 'create', 'update', 'delete'],
            'option-sets' => ['view', 'create', 'update', 'delete'],
            'inner-option-sets' => ['view', 'create', 'update', 'delete'],
            'recipes' => ['view', 'create', 'update', 'delete'],
            'ingredients' => ['view', 'create', 'update', 'delete'],
            'stock' => ['view', 'create', 'update', 'adjust'],
            'orders' => ['view', 'create', 'update', 'delete', 'cancel'],
            'customers' => ['view', 'create', 'update', 'delete'],
            'pos' => ['access', 'create-order', 'apply-discount'],
            'expenses' => ['view', 'create', 'update', 'delete'],
            'expense-categories' => ['view', 'create', 'update', 'delete'],
            'cash-flows' => ['view', 'create'],
            'analytics' => ['view-sales', 'view-orders', 'view-expenses', 'view-profitability', 'view-dashboard'],
            'batch-size-configs' => ['view', 'create', 'update', 'delete'],
        ];

        foreach ($modules as $module => $actions) {
            foreach ($actions as $action) {
                Permission::firstOrCreate([
                    'name' => "{$module}.{$action}",
                    'guard_name' => 'sanctum',
                ]);
            }
        }
    }
}
