<?php

namespace Modules\Admin\Database\seeders;

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

class RoleSeeder extends Seeder
{
    private $roles = [
        [
            'name'  => 'SuperAdmin',
            'style' => 'dark'
        ],
        [
            'name'  => 'Admin',
            'style' => 'primary'
        ],
        [
            'name'  => 'Administrador Web',
            'style' => 'primary'
        ],
        [
            'name'  => 'Editor',
            'style' => 'primary'
        ],
        [
            'name'  => 'Productos y servicios',
            'style' => 'info'
        ],
        [
            'name'  => 'Recursos humanos',
            'style' => 'success'
        ],
        [
            'name'  => 'Nómina',
            'style' => 'success'
        ],
        [
            'name'  => 'Activos fijos',
            'style' => 'secondary'
        ],
        [
            'name'  => 'Compras y gastos',
            'style' => 'info'
        ],
        [
            'name'  => 'CRM',
            'style' => 'warning'
        ],
        [
            'name'  => 'Vendedor',
            'style' => 'info'
        ],
        [
            'name'  => 'Gerente',
            'style' => 'danger'
        ],
        [
            'name'  => 'Facturación',
            'style' => 'info'
        ],
        [
            'name'  => 'Facturación avanzado',
            'style' => 'danger'
        ],
        [
            'name'  => 'Finanzas',
            'style' => 'info'
        ],
        [
            'name'  => 'Auditor',
            'style' => 'dark'
        ],
    ];

    private $permissions = [
        // Aplicación
        'webapp' => [
            'name' => 'Aplicación',
            'sub_groups' => [
                'general-settings' => [
                    'name' => 'Ajustes generales',
                    'actions' => [
                        'allow' => [],
                    ]
                ],
                'cache-manager' => [
                    'name' => 'Ajuests de caché',
                    'actions' => [
                        'view' => [],
                        'edit' => [],
                    ]
                ],
                'session-settings' => [
                    'name' => 'Ajustes de sesión',
                    'actions' => [
                        'view' => [],
                        'edit' => [],
                    ]
                ],
                'catalogs' => [
                    'name' => 'Catálogos',
                    'actions' => [
                        'view' => [
                            'Gerente',
                        ],
                        'create' => [
                            'Gerente',
                        ],
                        'edit' => [
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'api-banxico' => [
                    'name' => 'API BANXICO (Tipos de cambio)',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ],
                    ]
                ],
                'smtp-settings' => [
                    'name' => 'Servidor de correo SMTP',
                    'actions' => [
                        'allow' => [],
                    ]
                ],
            ]
        ],

        // Sitio Web
        'website' => [
            'name' => 'Sitio Web',
            'sub_groups' => [
                'general-settings' => [
                    'name' => 'Ajustes generales',
                    'actions' => [
                        'allow' => [
                            'Administrador Web',
                        ],
                    ]
                ],
                'slider' => [
                    'name' => 'Slider',
                    'actions' => [
                        'view' => [
                            'Administrador Web',
                        ],
                        'create' => [
                            'Administrador Web',
                        ],
                        'edit' => [
                            'Administrador Web',
                        ],
                        'delete' => [
                            'Administrador Web',
                        ]
                    ]
                ],
                'cmagazine' => [
                    'name' => 'Concierge Magazine',
                    'actions' => [
                        'view' => [
                            'Administrador Web',
                        ],
                        'create' => [
                            'Administrador Web',
                        ],
                        'edit' => [
                            'Administrador Web',
                        ],
                        'delete' => [
                            'Administrador Web',
                        ]
                    ]
                ],
                'faq' => [
                    'name' => 'Preguntas frecuentes',
                    'actions' => [
                        'view' => [
                            'Administrador Web',
                        ],
                        'create' => [
                            'Administrador Web',
                        ],
                        'edit' => [
                            'Administrador Web',
                        ],
                        'delete' => [
                            'Administrador Web',
                        ]
                    ]
                ],
                'legal' => [
                    'name' => 'Avisos legales',
                    'actions' => [
                        'view' => [
                            'Administrador Web',
                        ],
                        'edit' => [
                            'Administrador Web',
                        ],
                    ]
                ],
            ]
        ],

        // Empresa
        'company' => [
            'name' => 'Empresa',
            'sub_groups' => [
                'general-settings' => [
                    'name' => 'Ajustes generales',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ],
                    ]
                ],
                'stores' => [
                    'name' => 'Sucursales',
                    'actions' => [
                        'view' => [],
                        'create' => [],
                        'edit' => [],
                        'delete' => [],
                    ]
                ],
                'catalogs' => [
                    'name' => 'Catálogos',
                    'actions' => [
                        'view' => [
                            'Gerente',
                        ],
                        'create' => [
                            'Gerente',
                        ],
                        'edit' => [
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
            ]
        ],

        // Recursos humanos
        'human-resources' => [
            'name' => 'Recursos Humanos',
            'sub_groups' => [
                'dashboard' => [
                    'name' => 'Tablero',
                    'actions' => [
                        'allow' => [
                            'Recursos humanos',
                            'Gerente',
                        ]
                    ]
                ],
                'employees' => [
                    'name' => 'Empleados',
                    'actions' => [
                        'view' => [
                            'Recursos humanos',
                            'Gerente',
                        ],
                        'create' => [
                            'Recursos humanos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Recursos humanos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'jobs' => [
                    'name' => 'Puestos de trabajo',
                    'actions' => [
                        'view' => [
                            'Recursos humanos',
                            'Gerente',
                        ],
                        'create' => [
                            'Recursos humanos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Recursos humanos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
            ]
        ],

        // Nómina
        'payrolls' => [
            'name' => 'Nómina',
            'sub_groups' => [
                'dashboard' => [
                    'name' => 'Tablero',
                    'actions' => [
                        'allow' => [
                            'Nómina',
                            'Gerente',
                        ]
                    ]
                ],
                'contracts' => [
                    'name' => 'Contratos',
                    'actions' => [
                        'view' => [
                            'Nómina',
                            'Gerente',
                        ],
                        'create' => [
                            'Nómina',
                            'Gerente',
                        ],
                        'edit' => [
                            'Nómina',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'assistance' => [
                    'name' => 'Asistencias',
                    'actions' => [
                        'view' => [
                            'Nómina',
                            'Gerente',
                        ],
                        'create' => [
                            'Nómina',
                            'Gerente',
                        ],
                        'edit' => [
                            'Nómina',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
            ]
        ],

        // Activos fijos
        'assets' => [
            'name' => 'Activos fijos',
            'sub_groups' => [
                'assets' => [
                    'name' => 'Catálogo de activos',
                    'actions' => [
                        'view' => [
                            'Activos fijos',
                            'Gerente',
                        ],
                        'create' => [
                            'Activos fijos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Activos fijos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'events' => [
                    'name' => 'Eventos relacionados',
                    'actions' => [
                        'view' => [
                            'Activos fijos',
                            'Gerente',
                        ],
                        'create' => [
                            'Activos fijos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Activos fijos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
            ]
        ],

        // Gestión de Relación con los Clientes
        'crm' => [
            'name' => 'Gestión de Relación con los Clientes',
            'sub_groups' => [
                'contacts' => [
                    'name' => 'Contactos',
                    'actions' => [
                        'view' => [
                            'CRM',
                            'Gerente',
                        ],
                        'create' => [
                            'CRM',
                            'Gerente',
                        ],
                        'edit' => [
                            'CRM',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ]
                    ]
                ],
                'marketing-campaigns' => [
                    'name' => 'Campañas de marketing',
                    'actions' => [
                        'view' => [
                            'CRM',
                            'Gerente',
                        ],
                        'create' => [
                            'CRM',
                            'Gerente',
                        ],
                        'edit' => [
                            'CRM',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ]
                    ]
                ],
                'leads' => [
                    'name' => 'Oportunidades',
                    'actions' => [
                        'view' => [
                            'CRM',
                            'Gerente',
                        ],
                        'create' => [
                            'CRM',
                            'Gerente',
                        ],
                        'edit' => [
                            'CRM',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ]
                    ]
                ],
                'newsletter' => [
                    'name' => 'Newsletter',
                    'actions' => [
                        'view' => [
                            'Administrador Web',
                            'CRM',
                            'Gerente',
                        ],
                        'edit' => [
                            'Administrador Web',
                            'CRM',
                            'Gerente',
                        ],
                        'delete' => []
                    ]
                ],
            ]
        ],

        // Gastos y compras
        'purchases' => [
            'name' => 'Gastos y compras',
            'sub_groups' => [
                'dashboard' => [
                    'name' => 'Tablero',
                    'actions' => [
                        'allow' => [
                            'Compras y gastos',
                            'Gerente',
                        ]
                    ]
                ],
                'supplier' => [
                    'name' => 'Proveedores',
                    'actions' => [
                        'view' => [
                            'Compras y gastos',
                            'Gerente',
                            'Finanzas',
                        ],
                        'create' => [
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ]
                    ]
                ],
                'orders' => [
                    'name' => 'Órdenes de compras',
                    'actions' => [
                        'view' => [
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'create' => [
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ]
                    ]
                ],
                'purchases' => [
                    'name' => 'Compras y gastos',
                    'actions' => [
                        'view' => [
                            'Compras y gastos',
                            'Gerente',
                            'Finanzas',
                        ],
                        'create' => [
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ]
                    ]
                ],
            ]
        ],

        // Productos y servicios
        'products' => [
            'name' => 'Productos y servicios',
            'sub_groups' => [
                'categories' => [
                    'name' => 'Categorías de productos',
                    'actions' => [
                        'view' => [
                            'Productos y servicios',
                            'Activos fijos',
                            'Compras y gastos',
                            'Vendedor',
                            'Gerente',
                            'Facturación',
                            'Facturación avanzado',
                        ],
                        'create' => [
                            'Productos y servicios',
                            'Activos fijos',
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Productos y servicios',
                            'Activos fijos',
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'catalogs' => [
                    'name' => 'Catalogos de productos',
                    'actions' => [
                        'view' => [
                            'Productos y servicios',
                            'Gerente',
                        ],
                        'create' => [
                            'Productos y servicios',
                            'Gerente',
                        ],
                        'edit' => [
                            'Productos y servicios',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'products' => [
                    'name' => 'Productos',
                    'actions' => [
                        'view' => [
                            'Productos y servicios',
                            'Activos fijos',
                            'Compras y gastos',
                            'Vendedor',
                            'Gerente',
                            'Facturación',
                            'Facturación avanzado',
                        ],
                        'create' => [
                            'Productos y servicios',
                            'Activos fijos',
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'edit' => [
                            'Productos y servicios',
                            'Activos fijos',
                            'Compras y gastos',
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
            ],
        ],

        // Punto de venta
        'pos' => [
            'name' => 'Punto de venta',
            'sub_groups' => [
                'dashboard' => [
                    'name' => 'Tablero',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ],
                    ]
                ],
                'pricelists-config' => [
                    'name' => 'listas de precios',
                    'actions' => [
                        'view' => [
                            'Productos y servicios',
                            'Compras y gastos',
                            'Vendedor',
                            'Gerente',
                        ],
                        'create' => [
                            'Gerente',
                        ],
                        'edit' => [
                            'Gerente',
                        ],
                        'delete' => [],
                    ]
                ],
                'ticket-config' => [
                    'name' => 'Ticket de punto de venta',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ],
                    ]
                ],
                'catalogs' => [
                    'name' => 'Catalogos de punto de venta',
                    'actions' => [
                        'view' => [
                            'Productos y servicios',
                            'Gerente',
                        ],
                        'create' => [
                            'Productos y servicios',
                            'Gerente',
                        ],
                        'edit' => [
                            'Productos y servicios',
                            'Gerente',
                        ],
                        'delete' => [],
                    ]
                ],
                'customers' => [
                    'name' => 'Clientes',
                    'actions' => [
                        'view' => [
                            'Vendedor',
                            'Gerente',
                            'Facturación',
                            'Facturación avanzado',
                            'Finanzas',
                        ],
                        'create' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'edit' => [
                            'Vendedor',
                            'Gerente',
                            'Facturación',
                            'Facturación avanzado',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'quotes' => [
                    'name' => 'Cotizaciones',
                    'actions' => [
                        'view' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'create' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'edit' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'delete' => [
                            'Vendedor',
                            'Gerente',
                        ],
                    ]
                ],
                'sales' => [
                    'name' => 'Ventas',
                    'actions' => [
                        'view' => [
                            'Vendedor',
                            'Gerente',
                            'Facturación',
                            'Facturación avanzado',
                            'Finanzas',
                        ],
                        'create' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'edit' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'modify-sale-price' => [
                    'name' => 'Modificar precio de venta',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ],
                    ]
                ],
                'apply-discounts' => [
                    'name' => 'Aplicar descuentos',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ],
                    ]
                ],
                'allow-negative-iventory' => [
                    'name' => 'Permitir venta con inventario negativo',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ],
                    ]
                ],
                'remissions' => [
                    'name' => 'Remisiones',
                    'actions' => [
                        'view' => [
                            'Vendedor',
                            'Gerente',
                            'Finanzas',
                        ],
                        'create' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'edit' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'credit-notes' => [
                    'name' => 'Notas de crédito',
                    'actions' => [
                        'view' => [
                            'Vendedor',
                            'Gerente',
                            'Finanzas',
                        ],
                        'create' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'edit' => [
                            'Vendedor',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
            ]
        ],

        // Facturación
        'billing' => [
            'name' => 'Facturación',
            'sub_groups' => [
                'dashboard' => [
                    'name' => 'Tablero',
                    'actions' => [
                        'allow' => [
                            'Facturación avanzado',
                            'Gerente',
                        ]
                    ]
                ],
                'general-settings' => [
                    'name' => 'Configuraciones de facturación',
                    'actions' => [
                        'allow' => [
                            'Facturación avanzado',
                            'Gerente',
                        ],
                    ]
                ],
                'csds-settings' => [
                    'name' => 'Certificados de Sello Digital',
                    'actions' => [
                        'allow' => [
                            'Facturación avanzado',
                            'Gerente',
                        ],
                    ]
                ],
                'smtp-settings' => [
                    'name' => 'Correo SMTP de facturación',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ],
                    ]
                ],
                'stamping-package' => [
                    'name' => 'Paquete de timbrado',
                    'actions' => [
                        'allow' => [
                            'Facturación avanzado',
                            'Gerente',
                        ],
                    ]
                ],
                'ingresos' => [
                    'name' => 'Facturación CFDI Ingresos',
                    'actions' => [
                        'view' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ],
                        'create' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Facturación avanzado',
                            'Gerente',
                        ],
                    ]
                ],
                'egresos' => [
                    'name' => 'Facturación CFDI Egresos',
                    'actions' => [
                        'view' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ],
                        'create' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Facturación avanzado',
                            'Gerente',
                        ],
                    ]
                ],
                'pagos' => [
                    'name' => 'Facturación CFDI Pagos',
                    'actions' => [
                        'view' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ],
                        'create' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Facturación avanzado',
                            'Gerente',
                        ],
                    ]
                ],
                'nomina' => [
                    'name' => 'Facturación CFDI Nómina',
                    'actions' => [
                        'view' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ],
                        'create' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Facturación avanzado',
                            'Gerente',
                        ],
                    ]
                ],
                'verify-cfdi' => [
                    'name' => 'Verificador de CFDI 4.0',
                    'actions' => [
                        'allow' => [
                            'Facturación',
                            'Facturación avanzado',
                            'Gerente',
                        ]
                    ]
                ],
            ],
        ],

        // Finanzas
        'finance' => [
            'name' => 'Finanzas',
            'sub_groups' => [
                'dashboard' => [
                    'name' => 'Tablero',
                    'actions' => [
                        'allow' => [
                            'Finanzas',
                            'Gerente',
                        ]
                    ]
                ],
                'accounting-charts' => [
                    'name' => 'Catálogos de cuentas contables',
                    'actions' => [
                        'view' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'create' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'edit' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'accounts-payable' => [
                    'name' => 'Cuentas por pagar',
                    'actions' => [
                        'view' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'create' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'edit' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
                'accounts-receivable' => [
                    'name' => 'Cuentas por cobrar',
                    'actions' => [
                        'view' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'create' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'edit' => [
                            'Finanzas',
                            'Gerente',
                        ],
                        'cancel' => [
                            'Gerente',
                        ],
                        'delete' => [
                            'Gerente',
                        ],
                    ]
                ],
            ]
        ],

        // Blog
        'blog' => [
            'name' => 'Blog',
            'sub_groups' => [
                'categories' => [
                    'name' => 'Categorias',
                    'actions' => [
                        'view' => [
                            'Editor',
                        ],
                        'create' => [
                            'Editor',
                        ],
                        'edit' => [
                            'Editor',
                        ],
                        'delete' => [
                            'Editor',
                        ],
                    ]
                ],
                'tags' => [
                    'name' => 'Etiquetas',
                    'actions' => [
                        'view' => [
                            'Editor',
                        ],
                        'create' => [
                            'Editor',
                        ],
                        'edit' => [
                            'Editor',
                        ],
                        'delete' => [
                            'Editor',
                        ],
                    ]
                ],
                'articles' => [
                    'name' => 'Articulos',
                    'actions' => [
                        'view' => [
                            'Editor',
                        ],
                        'create' => [
                            'Editor',
                        ],
                        'edit' => [
                            'Editor',
                        ],
                        'delete' => [
                            'Editor',
                        ],
                    ]
                ],
                'comments' => [
                    'name' => 'Comentarios',
                    'actions' => [
                        'view' => [
                            'Editor',
                        ],
                        'create' => [
                            'Editor',
                        ],
                        'edit' => [
                            'Editor',
                        ],
                        'delete' => [
                            'Editor',
                        ],
                    ]
                ],
            ]
        ],

        // Sistema
        'system' => [
            'name' => 'Sistema',
            'sub_groups' => [
                'users' => [
                    'name' => 'Usuarios de sistema',
                    'actions' => [
                        'view' => [
                            'Gerente',
                        ],
                        'create' => [],
                        'edit' => [],
                        'delete' => []
                    ]
                ],
                'roles' => [
                    'name' => 'Roles de usuario',
                    'actions' => [
                        'view' => [
                            'Gerente',
                        ],
                        'create' => [],
                        'edit' => [],
                        'delete' => []
                    ]
                ],
                'permissions' => [
                    'name' => 'Permisos de usuarios',
                    'actions' => [
                        'view' => []
                    ]
                ]
            ]
        ],

        // Importación
        'import' => [
            'name' => 'Importar',
            'sub_groups' => [
                'catalogs-sat' => [
                    'name' => 'Importar Catálogos CFDI 4.0',
                    'actions' => [
                        'allow' => []
                    ]
                ]
            ]
        ],

        // Exportación
        'export' => [
            'name' => 'Exportar',
            'sub_groups' => [
                'customers' => [
                    'name' => 'Exportar clientes',
                    'actions' => [
                        'allow' => [
                            'Gerente',
                        ]
                    ]
                ]
            ]
        ],

    ];

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        foreach ($this->roles as $role) {
            Role::create($role);
        }

        $group_blockId = 0;

        foreach ($this->permissions as $group_idx => $group) {
            $sub_group_blockId = 0;

            foreach ($group['sub_groups'] as $sub_group_idx => $sub_group) {
                $action_id = 0;

                foreach ($sub_group['actions'] as $action => $roleNames) {
                    $roles_default = ['SuperAdmin'];

                    // Default Admin role
                    if ("{$group_idx}.{$sub_group_idx}" != 'system.permissions')
                        $roles_default[] = 'Admin';

                    // Default Auditor role
                    if ($sub_group_idx == 'dashboard' || $action == 'view')
                        $roles_default[] = 'Auditor';

                    Permission::create([
                        'id' => ($group_blockId * 1000) + ($sub_group_blockId * 10) + $action_id++,
                        'name' => "{$group_idx}.{$sub_group_idx}.{$action}",
                        'group_name' => $group['name'],
                        'sub_group_name' => $sub_group['name'],
                        'action' => $action,
                    ])->syncRoles(array_merge($roles_default, $roleNames));
                }

                $sub_group_blockId++;
            }

            $group_blockId++;
        }

        app()->make(\Spatie\Permission\PermissionRegistrar::class)->forgetCachedPermissions();
    }
}
