<?php

namespace Modules\Inventory\Database\Seeders;

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

class InventoryPermissionSeeder extends Seeder
{
    use HasModulePermissions;

    public function run(): void
    {
        $this->seedPermissions('inventory', [
            'setting' => [
                'view',
                'manage',
            ],

            'product' => [
                'view',
                'create',
                'update',
                'delete',
                'status',
            ],

            'purchase' => [
                'requisition-create',
                'requisition-view',
                'requisition-update',
                'requisition-delete',
                'requisition-approve',

                'create',
                'view',
                'update',
                'delete',
                'approve',
                'post',

                'payment-create',
                'payment-view',
                'payment-update',
                'payment-delete',
                'payment-approve',
                'payment-post',
            ],
        ]);

        Role::query()->where('name', RolesEnum::ADMIN->value)->first()?->givePermissionTo([
            'inventory.setting.view',
            'inventory.setting.manage',

            'inventory.product.view',
            'inventory.product.create',
            'inventory.product.update',
            'inventory.product.delete',
            'inventory.product.status',

            'inventory.purchase.requisition-view',
            'inventory.purchase.requisition-approve',

            'inventory.purchase.view',
            'inventory.purchase.approve',

            'inventory.purchase.payment-view',
            'inventory.purchase.payment-approve',
        ]);

        Role::query()->where('name', RolesEnum::ED->value)->first()?->givePermissionTo([
            'inventory.purchase.requisition-view',
            'inventory.purchase.requisition-approve',

            'inventory.purchase.payment-view',
            'inventory.purchase.payment-approve',
        ]);

        Role::query()->where('name', RolesEnum::MANAGER->value)->first()?->givePermissionTo([
            'inventory.purchase.requisition-view',
            'inventory.purchase.requisition-approve',

            'inventory.purchase.payment-view',
            'inventory.purchase.payment-approve',
        ]);

        Role::query()->where('name', RolesEnum::INVENTORY->value)->first()?->givePermissionTo([
            'inventory.product.view',
            'inventory.product.create',
            'inventory.product.update',
            'inventory.product.status',

            'inventory.purchase.requisition-create',
            'inventory.purchase.requisition-view',
            'inventory.purchase.requisition-update',
            'inventory.purchase.requisition-delete',

            'inventory.purchase.create',
            'inventory.purchase.view',
            'inventory.purchase.update',
            'inventory.purchase.delete',
            'inventory.purchase.post',

            'inventory.purchase.payment-create',
            'inventory.purchase.payment-view',
            'inventory.purchase.payment-update',
            'inventory.purchase.payment-post',
        ]);

        Role::query()->where('name', RolesEnum::ACCOUNTS->value)->first()?->givePermissionTo([
            'inventory.product.view',
            'inventory.purchase.view',

            'inventory.purchase.payment-create',
            'inventory.purchase.payment-view',
            'inventory.purchase.payment-update',
            'inventory.purchase.payment-delete',
            'inventory.purchase.payment-post',
        ]);
    }
}
