<?php

namespace Modules\Accounts\Database\Seeders;

use Illuminate\Database\Seeder;
use Modules\Auth\Models\Role;
use Modules\Core\Enums\RolesEnum;
use Modules\Core\Traits\HasModulePermissions;

class AccountPermissionSeeder extends Seeder
{
    use HasModulePermissions;

    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $this->seedPermissions('accounts', [
            'chart-of-accounts' => [
                'tree',
                'view',
                'create',
                'update',
                'delete',
                'status',
            ],
        ]);

        Role::where('name', RolesEnum::ADMIN->value)->first()?->givePermissionTo([
            'accounts.chart-of-accounts.tree',
            'accounts.chart-of-accounts.view',
            'accounts.chart-of-accounts.create',
            'accounts.chart-of-accounts.update',
            'accounts.chart-of-accounts.delete',
            'accounts.chart-of-accounts.status',
        ]);

        Role::where('name', RolesEnum::ACCOUNTS->value)->first()?->givePermissionTo([
            'accounts.chart-of-accounts.tree',
            'accounts.chart-of-accounts.view',
            'accounts.chart-of-accounts.create',
            'accounts.chart-of-accounts.update',
            'accounts.chart-of-accounts.status',
        ]);
    }
}
