<?php

namespace Database\Seeders;

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

class PermissionSeeder extends Seeder
{
    public function run(): void
    {
        $permissions = [
            [
                'key' => 'listing.view',
                'name' => 'View Listings',
                'description' => 'Can view listings.',
            ],
            [
                'key' => 'listing.create',
                'name' => 'Create Listing',
                'description' => 'Can create new listings.',
            ],
            [
                'key' => 'listing.update.own',
                'name' => 'Update Own Listing',
                'description' => 'Can update own listings.',
            ],
            [
                'key' => 'listing.delete.own',
                'name' => 'Delete Own Listing',
                'description' => 'Can delete own listings.',
            ],
            [
                'key' => 'listing.approve',
                'name' => 'Approve Listing',
                'description' => 'Can approve pending listings.',
            ],
            [
                'key' => 'listing.reject',
                'name' => 'Reject Listing',
                'description' => 'Can reject pending listings.',
            ],
            [
                'key' => 'consultant.profile.update.own',
                'name' => 'Update Own Consultant Profile',
                'description' => 'Can update own consultant profile.',
            ],
            [
                'key' => 'category.manage',
                'name' => 'Manage Categories',
                'description' => 'Can create, update and delete listing categories.',
            ],
            [
                'key' => 'feature.manage',
                'name' => 'Manage Features',
                'description' => 'Can create, update and delete listing features.',
            ],
            [
                'key' => 'user.manage',
                'name' => 'Manage Users',
                'description' => 'Can manage users and permissions.',
            ],
            [
                'key' => 'blog.manage',
                'name' => 'Manage blogs',
                'description' => 'Can manage blogs'
            ],
            [
                'key' => 'team.manage',
                'name' => 'Manage team members',
                'description' => 'Can manage team members'
            ],
            [
                'key' => 'consultant.manage',
                'name' => 'Manage consultant applications',
                'description' => 'Can review, approve and reject consultant (agent) applications.',
            ],
            [
                'key' => 'operations.manage',
                'name' => 'Run data operations',
                'description' => 'Can export/import listings via XML on the operations page.',
            ],
            [
                'key' => 'company.manage.own',
                'name' => 'Manage Own Company (Agency Panel)',
                'description' => 'Company owner: can manage own company profile, consultants and their listings.',
            ],
            [
                'key' => 'company.manage',
                'name' => 'Manage Companies',
                'description' => 'Admin: can review, approve, reject and verify company applications.',
            ]
        ];

        foreach ($permissions as $permission) {
            Permission::updateOrCreate(
                ['key' => $permission['key']],
                [
                    'name' => $permission['name'],
                    'description' => $permission['description'],
                    'is_active' => true,
                ]
            );
        }
    }
}