<?php

namespace Database\Seeders;

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

class PermissionSeeder extends Seeder
{
    public function run(): void
    {
        app(PermissionRegistrar::class)->forgetCachedPermissions();

        $permissions = [
            'conversations.view_all',
            'conversations.view_assigned',
            'conversations.reply',
            'conversations.assign',
            'conversations.close',
            'contacts.view',
            'contacts.manage',
            'leads.view',
            'leads.manage',
            'leads.move_stage',
            'products.manage',
            'quotes.manage',
            'orders.manage',
            'orders.update_payment',
            'reports.view',
            'reports.view_revenue',
            'users.manage',
            'roles.manage',
            'channels.manage',
            'billing.manage',
            'audit.view',
            'exports.run',
            'ai.use_reply_suggestions',
            'ai.use_summaries',
            'ai.use_intent_tools',
            'ai.use_lead_scoring',
            'ai.use_followup_generation',
            'ai.view_ai_usage',
            'ai.manage_settings',
        ];

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

        app(PermissionRegistrar::class)->forgetCachedPermissions();
    }
}
