<?php

namespace Database\Seeders;

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

class PermissionSeeder extends Seeder
{
    // php artisan db:seed --class=PermissionSeeder
    public function run()
    {
        $permissions = [
            ['id' => '1',  'name' => 'Dashboard',                     'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '2',  'name' => 'Total Loan Disbursement',       'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '3',  'name' => 'Total Principal Paid',          'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '4',  'name' => 'Total Received',                'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '5',  'name' => 'Balance Principal',             'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '6',  'name' => 'Total Clients',                 'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '7',  'name' => 'Total Client Late',             'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '8',  'name' => 'Total Client Disbursement Today','guard_name'=> 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '9',  'name' => 'Total Income',                  'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '10', 'name' => 'Total Expense',                 'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '11', 'name' => 'Net Profit / Loss',             'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '12', 'name' => 'Total Loan Disbursed Daily',    'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '13', 'name' => 'Total Client Detail',           'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '14', 'name' => 'Income / Expense',              'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            ['id' => '15', 'name' => 'Daily Repay',                   'guard_name' => 'web', 'group_prefix' => 'Dashboard'],
            // Currency
            ['id' => '16', 'name' => 'Currency List',         'guard_name'  => 'web','group_prefix' => 'Currency'],
            ['id' => '17', 'name' => 'Currency Create',       'guard_name'  => 'web','group_prefix' => 'Currency'],
            ['id' => '18', 'name' => 'Currency Edit',         'guard_name'  => 'web','group_prefix' => 'Currency'],
            ['id' => '19', 'name' => 'Currency Delete',       'guard_name'  => 'web','group_prefix' => 'Currency'],
            // Holiday
            ['id' => '20', 'name' => 'Holiday List',          'guard_name'  => 'web','group_prefix' => 'Holiday'],
            ['id' => '21', 'name' => 'Holiday Create',        'guard_name'  => 'web','group_prefix' => 'Holiday'],
            ['id' => '22', 'name' => 'Holiday Edit',          'guard_name'  => 'web','group_prefix' => 'Holiday'],
            ['id' => '23', 'name' => 'Holiday Delete',        'guard_name'  => 'web','group_prefix' => 'Holiday'],
            // Settings
            ['id' => '24', 'name' => 'Settings',              'guard_name'  => 'web','group_prefix' => 'Settings'],
            ['id' => '25', 'name' => 'Backup',                'guard_name'  => 'web','group_prefix' => 'Settings'],
            ['id' => '26', 'name' => 'Company List',          'guard_name'  => 'web','group_prefix' => 'Settings'],
            ['id' => '27', 'name' => 'Logactivity List',      'guard_name'  => 'web','group_prefix' => 'Settings'],
            // Users
            ['id' => '28', 'name' => 'User List',             'guard_name'  => 'web','group_prefix' => 'Users'],
            ['id' => '29', 'name' => 'User Create',           'guard_name'  => 'web','group_prefix' => 'Users'],
            ['id' => '30', 'name' => 'User Edit',             'guard_name'  => 'web','group_prefix' => 'Users'],
            ['id' => '31', 'name' => 'User Delete',           'guard_name'  => 'web','group_prefix' => 'Users'],
            // User Roles
            ['id' => '32', 'name' => 'User Role List',        'guard_name'  => 'web','group_prefix' => 'User Roles'],
            ['id' => '33', 'name' => 'User Role Create',      'guard_name'  => 'web','group_prefix' => 'User Roles'],
            ['id' => '34', 'name' => 'User Role Edit',        'guard_name'  => 'web','group_prefix' => 'User Roles'],
            ['id' => '35', 'name' => 'User Role Delete',      'guard_name'  => 'web','group_prefix' => 'User Roles'],
            // Clients
            ['id' => '36', 'name' => 'Client List',           'guard_name'  => 'web','group_prefix' => 'Clients'],
            ['id' => '37', 'name' => 'Client Create',         'guard_name'  => 'web','group_prefix' => 'Clients'],
            ['id' => '38', 'name' => 'Client Edit',           'guard_name'  => 'web','group_prefix' => 'Clients'],
            ['id' => '39', 'name' => 'Client Delete',         'guard_name'  => 'web','group_prefix' => 'Clients'],
            // Credit Officer
            ['id' => '40', 'name' => 'Co List',               'guard_name'  => 'web','group_prefix' => 'Credit Officer'],
            ['id' => '41', 'name' => 'Co Create',             'guard_name'  => 'web','group_prefix' => 'Credit Officer'],
            ['id' => '42', 'name' => 'Co Edit',               'guard_name'  => 'web','group_prefix' => 'Credit Officer'],
            ['id' => '43', 'name' => 'Co Delete',             'guard_name'  => 'web','group_prefix' => 'Credit Officer'],
            // Categories
            ['id' => '44', 'name' => 'Category List',         'guard_name'  => 'web','group_prefix' => 'Categories'],
            ['id' => '45', 'name' => 'Category Create',       'guard_name'  => 'web','group_prefix' => 'Categories'],
            ['id' => '46', 'name' => 'Category Edit',         'guard_name'  => 'web','group_prefix' => 'Categories'],
            ['id' => '47', 'name' => 'Category Delete',       'guard_name'  => 'web','group_prefix' => 'Categories'],
            // Collateral
            ['id' => '48', 'name' => 'Collateral List',       'guard_name'  => 'web','group_prefix' => 'Collateral'],
            ['id' => '49', 'name' => 'Collateral Create',     'guard_name'  => 'web','group_prefix' => 'Collateral'],
            ['id' => '50', 'name' => 'Collateral Edit',       'guard_name'  => 'web','group_prefix' => 'Collateral'],
            ['id' => '51', 'name' => 'Collateral Delete',     'guard_name'  => 'web','group_prefix' => 'Collateral'],
            // Loans
            ['id' => '52', 'name' => 'Loan List',             'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '53', 'name' => 'Loan Create',           'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '54', 'name' => 'Loan Edit',             'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '55', 'name' => 'Loan Reschedule',       'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '56', 'name' => 'Loan Credit Card',      'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '57', 'name' => 'Loan Delete',           'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '58', 'name' => 'Contract Loan',         'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '59', 'name' => 'Loan Table Schedule',   'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '60', 'name' => 'Loan Approve',          'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '61', 'name' => 'History Payment',       'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '62', 'name' => 'List Approve',          'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '63', 'name' => 'Move CO',               'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '64', 'name' => 'Move To Write Off',     'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '65', 'name' => 'Write Off List',        'guard_name'  => 'web','group_prefix' => 'Loans'],
            ['id' => '66', 'name' => 'Loan Collateral Create','guard_name'  => 'web','group_prefix' => 'Loans'],
            // Payments
            ['id' => '67', 'name' => 'Payment List',           'guard_name' => 'web','group_prefix' => 'Payments'],
            ['id' => '68', 'name' => 'Repay',                  'guard_name' => 'web','group_prefix' => 'Payments'],
            ['id' => '69', 'name' => 'Pay Off',                'guard_name' => 'web','group_prefix' => 'Payments'],
            ['id' => '70', 'name' => 'Repay Edit',             'guard_name' => 'web','group_prefix' => 'Payments'],
            ['id' => '71', 'name' => 'Repay Delete',           'guard_name' => 'web','group_prefix' => 'Payments'],
            ['id' => '72', 'name' => 'Collect Good List',      'guard_name' => 'web','group_prefix' => 'Payments'],
            ['id' => '73', 'name' => 'Collect Late List',      'guard_name' => 'web','group_prefix' => 'Payments'],
            ['id' => '74', 'name' => 'Collect Write Off List', 'guard_name' => 'web','group_prefix' => 'Payments'],
            // Client Payments
            ['id' => '75', 'name' => 'Client Payment List',    'guard_name' => 'web','group_prefix' => 'Client Payments'],
            ['id' => '76', 'name' => 'Co Received Report',     'guard_name' => 'web','group_prefix' => 'Client Payments'],
            ['id' => '77', 'name' => 'Cashier Received Report','guard_name' => 'web','group_prefix' => 'Client Payments'],
            ['id' => '78', 'name' => 'Closing Report',         'guard_name' => 'web','group_prefix' => 'Client Payments'],
            ['id' => '79', 'name' => 'Submit Closing Report',  'guard_name' => 'web','group_prefix' => 'Client Payments'],
            ['id' => '80', 'name' => 'Edit Closing Report',    'guard_name' => 'web','group_prefix' => 'Client Payments'],
            // Reports
            ['id' => '81', 'name' => 'Credit Officer Report',  'guard_name' => 'web','group_prefix' => 'Reports'],
            ['id' => '82', 'name' => 'Daily Report',           'guard_name' => 'web','group_prefix' => 'Reports'],
            ['id' => '83', 'name' => 'Loan Repayment Report',  'guard_name' => 'web','group_prefix' => 'Reports'],
            ['id' => '84', 'name' => 'Loan Arrear Report',     'guard_name' => 'web','group_prefix' => 'Reports'],
            ['id' => '85', 'name' => 'Borrow Report',          'guard_name' => 'web','group_prefix'=> 'Reports'],
            ['id' => '86', 'name' => 'Overdue Report',         'guard_name' => 'web','group_prefix' => 'Reports'],
            ['id' => '87', 'name' => 'Collected Report',       'guard_name' => 'web','group_prefix' => 'Reports'],
            ['id' => '88', 'name' => 'Loan Pay Off Report',    'guard_name' => 'web','group_prefix' => 'Reports'],
            ['id' => '89', 'name' => 'Summary Co Report',      'guard_name' => 'web','group_prefix' => 'Reports'],
            ['id' => '90', 'name' => 'Collateral Report',      'guard_name' => 'web','group_prefix' => 'Reports'],
            // Type Account
            ['id' => '91', 'name' => 'Type Account List',      'guard_name' => 'web','group_prefix' => 'Type Account'],
            ['id' => '92', 'name' => 'Type Account Create',    'guard_name' => 'web','group_prefix' => 'Type Account'],
            ['id' => '93', 'name' => 'Type Account Edit',      'guard_name' => 'web','group_prefix' => 'Type Account'],
            ['id' => '94', 'name' => 'Type Account Delete',    'guard_name' => 'web','group_prefix' => 'Type Account'],
            // Chart Of Account
            ['id' => '95', 'name' => 'ChartOfAccount List',    'guard_name' => 'web','group_prefix' => 'Chart Of Account'],
            ['id' => '96', 'name' => 'ChartOfAccount Create',  'guard_name' => 'web','group_prefix' => 'Chart Of Account'],
            ['id' => '97', 'name' => 'ChartOfAccount Edit',    'guard_name' => 'web','group_prefix' => 'Chart Of Account'],
            ['id' => '98', 'name' => 'ChartOfAccount Delete',  'guard_name' => 'web','group_prefix' => 'Chart Of Account'],
            // Asset
            ['id' => '99', 'name' => 'Asset List',             'guard_name' => 'web','group_prefix' => 'Asset'],
            ['id' => '100', 'name' => 'Asset Create',          'guard_name' => 'web','group_prefix' => 'Asset'],
            ['id' => '101', 'name' => 'Asset Edit',            'guard_name' => 'web','group_prefix' => 'Asset'],
            ['id' => '102', 'name' => 'Asset Delete',          'guard_name' => 'web','group_prefix' => 'Asset'],
            // Depreciation
            ['id' => '103', 'name' => 'Depreciation List',      'guard_name' => 'web','group_prefix' => 'Depreciation'],
            ['id' => '104','name' => 'Depreciation Create',    'guard_name' => 'web','group_prefix' => 'Depreciation'],
            ['id' => '105','name' => 'Depreciation Edit',      'guard_name' => 'web','group_prefix' => 'Depreciation'],
            ['id' => '106','name' => 'Depreciation Show',      'guard_name' => 'web','group_prefix' => 'Depreciation'],
            ['id' => '107','name' => 'Depreciation Print',     'guard_name' => 'web','group_prefix' => 'Depreciation'],
            ['id' => '108','name' => 'Depreciation Delete',    'guard_name' => 'web','group_prefix' => 'Depreciation'],
            // Expense
            ['id' => '109','name' => 'Expense List',           'guard_name' => 'web','group_prefix' => 'Expense'],
            ['id' => '110','name' => 'Expense Create',         'guard_name' => 'web','group_prefix' => 'Expense'],
            ['id' => '111','name' => 'Expense Edit',           'guard_name' => 'web','group_prefix' => 'Expense'],
            ['id' => '112','name' => 'Expense Delete',         'guard_name' => 'web','group_prefix' => 'Expense'],
            // Income
            ['id' => '113','name' => 'Income List',            'guard_name' => 'web','group_prefix' => 'Income'],
            ['id' => '114','name' => 'Income Create',          'guard_name' => 'web','group_prefix' => 'Income'],
            ['id' => '115','name' => 'Income Edit',            'guard_name' => 'web','group_prefix' => 'Income'],
            ['id' => '116','name' => 'Income Delete',          'guard_name' => 'web','group_prefix' => 'Income'],
            // Journals
            ['id' => '117','name' => 'Journal List',           'guard_name' => 'web','group_prefix' => 'Journals'],
            ['id' => '118','name' => 'Journal Create',         'guard_name' => 'web','group_prefix' => 'Journals'],
            ['id' => '119','name' => 'Journal Edit',           'guard_name' => 'web','group_prefix' => 'Journals'],
            ['id' => '120','name' => 'Journal Delete',         'guard_name' => 'web','group_prefix' => 'Journals'],
            // Financial Reports
            ['id' => '121','name' => 'Expense Report',         'guard_name' => 'web','group_prefix' => 'Financial Reports'],
            ['id' => '122','name' => 'Income Report',          'guard_name' => 'web','group_prefix' => 'Financial Reports'],
            ['id' => '123','name' => 'Journal Report',         'guard_name' => 'web','group_prefix' => 'Financial Reports'],
            ['id' => '124','name' => 'Net Loss Profit',        'guard_name' => 'web','group_prefix' => 'Financial Reports'],
            ['id' => '125','name' => 'TrialBalance Report',    'guard_name' => 'web','group_prefix' => 'Financial Reports'],
            ['id' => '126','name' => 'GeneralLedger Report',   'guard_name' => 'web','group_prefix' => 'Financial Reports'],
            ['id' => '127','name' => 'CashFlow Report',        'guard_name' => 'web','group_prefix' => 'Financial Reports'],
            ['id' => '128','name' => 'BalanceSheet Report',    'guard_name' => 'web','group_prefix' => 'Financial Reports'],
            // Saving
            ['id' => '129','name' => 'Saving List',            'guard_name' => 'web','group_prefix' => 'Saving'],
            ['id' => '130','name' => 'Saving Request',         'guard_name' => 'web','group_prefix' => 'Saving'],
            ['id' => '131','name' => 'Saving Approve',         'guard_name' => 'web','group_prefix' => 'Saving'],
            ['id' => '132','name' => 'Saving Reject',          'guard_name' => 'web','group_prefix' => 'Saving'],
            // Branch
            ['id' => '133','name' => 'Branch List',            'guard_name' => 'web','group_prefix' => 'Branch'],
            ['id' => '134','name' => 'Branch Create',          'guard_name' => 'web','group_prefix' => 'Branch'],
            ['id' => '135','name' => 'Branch Edit',            'guard_name' => 'web','group_prefix' => 'Branch'],
            ['id' => '136','name' => 'Branch Delete',          'guard_name' => 'web','group_prefix' => 'Branch'],
            // Banknote Management
            ['id' => '137','name' => 'Daily Banknote Management',  'guard_name' => 'web','group_prefix' => 'Banknote Management'],
            ['id' => '138','name' => 'Banknote Management List',   'guard_name' => 'web','group_prefix' => 'Banknote Management'],
            ['id' => '139','name' => 'Banknote Management Create', 'guard_name' => 'web','group_prefix' => 'Banknote Management'],
            ['id' => '140','name' => 'Banknote Management Edit',   'guard_name' => 'web','group_prefix' => 'Banknote Management'],
            ['id' => '141','name' => 'Banknote Management Print',  'guard_name' => 'web','group_prefix' => 'Banknote Management'],
            ['id' => '142','name' => 'Banknote Management Delete', 'guard_name' => 'web','group_prefix' => 'Banknote Management'],
            // Manage Group CO
            // ['id' => '143','name' => 'Manage Group CO List',       'guard_name' => 'web','group_prefix' => 'Manage Group CO'],
            // ['id' => '144','name' => 'Manage Group CO Create',     'guard_name' => 'web','group_prefix' => 'Manage Group CO'],
            // ['id' => '145','name' => 'Manage Group CO Edit',       'guard_name' => 'web','group_prefix' => 'Manage Group CO'],
            // ['id' => '146','name' => 'Manage Group CO Delete',     'guard_name' => 'web','group_prefix' => 'Manage Group CO'],

        ];
        foreach ($permissions as  $value) {
            Permission::updateOrCreate(['id' => $value['id']], [
                'name' => $value['name'],
                'group_prefix' => $value['group_prefix'],
            ]);
        }

        $managing_director = [
            ['id' => 19],
            ['id' => 23],
            ['id' => 31],
            ['id' => 35],
            ['id' => 39],
            ['id' => 43],
            ['id' => 47],
            ['id' => 51],
            ['id' => 94],
            ['id' => 98],
            ['id' => 102],
            ['id' => 108],
            ['id' => 112],
            ['id' => 116],
            ['id' => 120],
            ['id' => 128],
            ['id' => 132],
            ['id' => 136],
            ['id' => 142],
            // ['id' => 146],
        ];

        $per_ceo = Permission::pluck('id', 'id')->all();
        $per_managing_director = Permission::whereNotIn('id',$managing_director)->pluck('id','id');

        $role1 = Role::find(1);
        $role2 = Role::find(2);

        $role1->syncPermissions($per_ceo);
        $role2->syncPermissions($per_managing_director);

        $user1 = User::find(1);
        $user1->assignRole([$role1->id]);
    }
}
