<?php

namespace Database\Seeders;

use App\Models\Department;
use App\Services\VisibilityService;
use Illuminate\Database\Seeder;

class DepartmentVisibilitySeeder extends Seeder
{
    public function run()
    {
        $visibility = app(VisibilityService::class);

        $designPermissions = [
            'leads.design_tasks',
            'leads.view',
            'leads.remarks',
            'leads.status',
            'tasks.cad',
            'tasks.general',
        ];

        $cad = Department::firstOrCreate(
            ['slug' => 'cad'],
            ['name' => 'CAD', 'description' => 'CAD team', 'is_active' => true]
        );
        $visibility->syncDepartmentPermissions($cad->id, $designPermissions);

        $designer3d = Department::firstOrCreate(
            ['slug' => '3d-designer'],
            ['name' => '3D Designer', 'description' => '3D design team', 'is_active' => true]
        );
        $visibility->syncDepartmentPermissions($designer3d->id, $designPermissions);

        $cam = Department::firstOrCreate(
            ['slug' => 'cam'],
            ['name' => 'CAM', 'description' => 'CAM team', 'is_active' => true]
        );
        $visibility->syncDepartmentPermissions($cam->id, [
            'leads.dashboard',
            'leads.listing',
            'leads.view',
            'leads.remarks',
            'tasks.cam',
        ]);

        $operations = Department::firstOrCreate(
            ['slug' => 'operations'],
            ['name' => 'Operations', 'description' => 'Operations team', 'is_active' => true]
        );
        $visibility->syncDepartmentPermissions($operations->id, [
            'leads.dashboard',
            'leads.listing',
            'leads.view',
            'tasks.operations',
        ]);

        $sales = Department::firstOrCreate(
            ['slug' => 'sales'],
            ['name' => 'Sales', 'description' => 'Sales team', 'is_active' => true]
        );
        $visibility->syncDepartmentPermissions($sales->id, [
            'leads.dashboard',
            'leads.listing',
            'leads.create',
            'leads.view',
            'leads.edit',
            'leads.status',
            'leads.remarks',
            'leads.assign',
            'vendor_quotes.manage',
            'tradefairs.manage',
            'users.manage',
            'masters.roles',
            'masters.departments',
        ]);

        $marketing = Department::firstOrCreate(
            ['slug' => 'marketing'],
            ['name' => 'Marketing', 'description' => 'Marketing team', 'is_active' => true]
        );
        $visibility->syncDepartmentPermissions($marketing->id, [
            'leads.my_tasks',
            'leads.view',
            'leads.remarks',
            'leads.status',
            'leads.edit.assigned',
            'vendor_quotes.manage',
            'leads.assign.design',
        ]);
    }
}
