<?php

namespace Database\Seeders;

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

class DesignerPermissionsSeeder extends Seeder
{
    public function run(): void
    {
        // Create designer permissions
        $permissions = [
            'view designers',
            'create designers',
            'edit designers',
            'delete designers',
            'restore designers',
            'force delete designers',
        ];

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

        // Assign permissions to admin role
        $adminRole = Role::firstOrCreate(['name' => 'admin']);
        $adminRole->givePermissionTo($permissions);

        // Assign permissions to moderator role
        $moderatorRole = Role::firstOrCreate(['name' => 'moderator']);
        $moderatorRole->givePermissionTo([
            'view designers',
            'edit designers',
        ]);

        // Assign permissions to editor role
        $editorRole = Role::firstOrCreate(['name' => 'editor']);
        $editorRole->givePermissionTo([
            'view designers',
            'create designers',
            'edit designers',
        ]);
    }
}