-- Migration: Add HR-specific permissions for role assignment and attendance management
-- This allows HR to assign roles to employees and manage attendance

-- Add new permissions
INSERT INTO `permissions` (`permission_code`, `permission_name`, `permission_module`, `permission_description`) VALUES
('EMPLOYEE_ROLE_ASSIGN', 'Assign Role to Employee', 'employee', 'Assign roles to employees'),
('ATTENDANCE_MARK_OWN', 'Mark Own Attendance', 'attendance', 'Mark attendance for self'),
('ATTENDANCE_MARK_EMPLOYEE', 'Mark Employee Attendance', 'attendance', 'Mark attendance for employees'),
('ATTENDANCE_REPORT', 'Generate Attendance Reports', 'attendance', 'Create and view attendance reports')
ON DUPLICATE KEY UPDATE 
    permission_name = VALUES(permission_name),
    permission_module = VALUES(permission_module),
    permission_description = VALUES(permission_description);

-- Assign these permissions to HR_ADMIN role (role_id = 2)
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT 2, permission_id FROM permissions 
WHERE permission_code IN ('EMPLOYEE_ROLE_ASSIGN', 'ATTENDANCE_MARK_OWN', 'ATTENDANCE_MARK_EMPLOYEE', 'ATTENDANCE_REPORT')
ON DUPLICATE KEY UPDATE role_id = role_id;

