<?php

namespace Database\Seeders;

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

class PermissionSeeder extends Seeder
{
    public function run(): void
    {
        $permissions = [
            // ==========================================================
            // HR MODULE
            // ==========================================================
            
            // HR Core - Masters
            ['name' => 'view-departments', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'create-departments', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'edit-departments', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'delete-departments', 'module' => 'HR', 'submodule' => 'Core'],

            ['name' => 'view-designations', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'create-designations', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'edit-designations', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'delete-designations', 'module' => 'HR', 'submodule' => 'Core'],

            ['name' => 'view-teams', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'create-teams', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'edit-teams', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'delete-teams', 'module' => 'HR', 'submodule' => 'Core'],

            ['name' => 'view-employment-types', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'create-employment-types', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'edit-employment-types', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'delete-employment-types', 'module' => 'HR', 'submodule' => 'Core'],

            ['name' => 'view-grades', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'create-grades', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'edit-grades', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'delete-grades', 'module' => 'HR', 'submodule' => 'Core'],

            ['name' => 'view-leave-types', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'create-leave-types', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'edit-leave-types', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'delete-leave-types', 'module' => 'HR', 'submodule' => 'Core'],

            // HR Core - Shift Roster
            ['name' => 'view-shift-settings', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'create-shift-settings', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'edit-shift-settings', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'delete-shift-settings', 'module' => 'HR', 'submodule' => 'Core'],

            ['name' => 'view-shift-segments', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'create-shift-segments', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'edit-shift-segments', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'delete-shift-segments', 'module' => 'HR', 'submodule' => 'Core'],

            ['name' => 'view-shift-calendar', 'module' => 'HR', 'submodule' => 'Core'],
            ['name' => 'manage-shift-calendar', 'module' => 'HR', 'submodule' => 'Core'],

            // HR Core - Employees
            ['name' => 'view-employees', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'create-employees', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'edit-employees', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'delete-employees', 'module' => 'HR', 'submodule' => 'Employees'],

            ['name' => 'view-employee-exits', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'create-employee-exits', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'edit-employee-exits', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'delete-employee-exits', 'module' => 'HR', 'submodule' => 'Employees'],

            ['name' => 'view-employee-rejoins', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'create-employee-rejoins', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'edit-employee-rejoins', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'delete-employee-rejoins', 'module' => 'HR', 'submodule' => 'Employees'],

            ['name' => 'view-gratuities', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'create-gratuities', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'edit-gratuities', 'module' => 'HR', 'submodule' => 'Employees'],
            ['name' => 'delete-gratuities', 'module' => 'HR', 'submodule' => 'Employees'],

            // Attendance
            ['name' => 'view-attendance-settings', 'module' => 'HR', 'submodule' => 'Attendance'],
            ['name' => 'create-attendance-settings', 'module' => 'HR', 'submodule' => 'Attendance'],
            ['name' => 'edit-attendance-settings', 'module' => 'HR', 'submodule' => 'Attendance'],
            ['name' => 'delete-attendance-settings', 'module' => 'HR', 'submodule' => 'Attendance'],

            ['name' => 'import-attendance-csv', 'module' => 'HR', 'submodule' => 'Attendance'],
            ['name' => 'view-attendance-employeewise', 'module' => 'HR', 'submodule' => 'Attendance'],
            ['name' => 'manage-attendance-employeewise', 'module' => 'HR', 'submodule' => 'Attendance'],
            ['name' => 'view-attendance-datewise', 'module' => 'HR', 'submodule' => 'Attendance'],

            // Leave
            ['name' => 'view-leave-applications', 'module' => 'HR', 'submodule' => 'Leave'],
            ['name' => 'create-leave-applications', 'module' => 'HR', 'submodule' => 'Leave'],
            ['name' => 'delete-leave-applications', 'module' => 'HR', 'submodule' => 'Leave'],

            // Payroll
            ['name' => 'view-payroll-groups', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'create-payroll-groups', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'edit-payroll-groups', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'delete-payroll-groups', 'module' => 'HR', 'submodule' => 'Payroll'],

            ['name' => 'view-payroll-additions', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'create-payroll-additions', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'edit-payroll-additions', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'delete-payroll-additions', 'module' => 'HR', 'submodule' => 'Payroll'],

            ['name' => 'view-payroll-deductions', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'create-payroll-deductions', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'edit-payroll-deductions', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'delete-payroll-deductions', 'module' => 'HR', 'submodule' => 'Payroll'],

            ['name' => 'view-payroll-loan-types', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'create-payroll-loan-types', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'edit-payroll-loan-types', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'delete-payroll-loan-types', 'module' => 'HR', 'submodule' => 'Payroll'],

            ['name' => 'view-payroll-loan-applications', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'create-payroll-loan-applications', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'edit-payroll-loan-applications', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'delete-payroll-loan-applications', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'approve-payroll-loan-applications', 'module' => 'HR', 'submodule' => 'Payroll'],

            ['name' => 'view-payroll-adjustments', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'create-payroll-adjustments', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'edit-payroll-adjustments', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'delete-payroll-adjustments', 'module' => 'HR', 'submodule' => 'Payroll'],

            ['name' => 'view-payroll-process', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'create-payroll-process', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'delete-payroll-process', 'module' => 'HR', 'submodule' => 'Payroll'],
            ['name' => 'execute-payroll-process', 'module' => 'HR', 'submodule' => 'Payroll'],

            // HR Reports
            ['name' => 'report-employee-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-employee-photo', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-employee-birthday', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-basic-salary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-payment-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-addition-deduction-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-employee-recruitment', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-employee-rejoin', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-employee-termination', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-employee-services', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-employee-appointment', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-male-female-ratio', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-head-count', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-missed-punches', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-absenteeism-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-subsequent-absenteeism-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-late-coming-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-late-coming-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-absenteeism-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-presenteeism-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-presenteeism-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-attendance-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-attendance-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-cadre', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-overtime-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-overtime-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-timesheet-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-timesheet-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-leave-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-leave-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-payroll-details-crosstab', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-loan-advance-details', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-loan-advance-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-cash-denominations', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-payslip', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-payroll-total-summary', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-payroll-signature', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-salary-bank-file', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-epf-evemc-creator', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-epf-evemp-creator', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-etf-bank-file', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-epf-report', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-epf-report-crosstab', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-etf-report', 'module' => 'HR', 'submodule' => 'Reports'],
            ['name' => 'report-etf-report-crosstab', 'module' => 'HR', 'submodule' => 'Reports'],

            // ==========================================================
            // PLATFORM MODULE
            // ==========================================================
            
            // Access Control
            ['name' => 'view-roles', 'module' => 'PLATFORM', 'submodule' => 'Access Control'],
            ['name' => 'create-roles', 'module' => 'PLATFORM', 'submodule' => 'Access Control'],
            ['name' => 'edit-roles', 'module' => 'PLATFORM', 'submodule' => 'Access Control'],
            ['name' => 'delete-roles', 'module' => 'PLATFORM', 'submodule' => 'Access Control'],

            ['name' => 'view-users', 'module' => 'PLATFORM', 'submodule' => 'Access Control'],
            ['name' => 'create-users', 'module' => 'PLATFORM', 'submodule' => 'Access Control'],
            ['name' => 'edit-users', 'module' => 'PLATFORM', 'submodule' => 'Access Control'],
            ['name' => 'delete-users', 'module' => 'PLATFORM', 'submodule' => 'Access Control'],

            // General Settings
            ['name' => 'view-companies', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-companies', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-companies', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-companies', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            ['name' => 'view-branches', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-branches', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-branches', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-branches', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            ['name' => 'view-currencies', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-currencies', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-currencies', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-currencies', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            ['name' => 'view-time-zones', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-time-zones', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-time-zones', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-time-zones', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            // Location & Region
            ['name' => 'view-countries', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-countries', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-countries', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-countries', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            ['name' => 'view-states', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-states', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-states', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-states', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            ['name' => 'view-cities', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-cities', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-cities', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-cities', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            // Payments
            ['name' => 'view-payment-methods', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-payment-methods', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-payment-methods', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-payment-methods', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            ['name' => 'view-banks', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-banks', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-banks', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-banks', 'module' => 'PLATFORM', 'submodule' => 'Settings'],

            ['name' => 'view-bank-branches', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'create-bank-branches', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'edit-bank-branches', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
            ['name' => 'delete-bank-branches', 'module' => 'PLATFORM', 'submodule' => 'Settings'],
        ];

        foreach ($permissions as $permission) {
            Permission::updateOrCreate(
                ['name' => $permission['name'], 'guard_name' => 'web'],
                ['module' => $permission['module'], 'submodule' => $permission['submodule']]
            );
        }
    }
}
