CREATE TABLE IF NOT EXISTS `roles` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `name` VARCHAR(255) NOT NULL UNIQUE
);

INSERT INTO `roles` (name) VALUES ('Admin'), ('HR'), ('Manager'), ('Employee');

CREATE TABLE IF NOT EXISTS `permissions` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `name` VARCHAR(255) NOT NULL UNIQUE
);

INSERT INTO `permissions` (name) VALUES
('view_dashboard'),
('manage_candidates'),
('manage_tasks'),
('manage_users'),
('view_reports');

CREATE TABLE IF NOT EXISTS `role_permissions` (
  `role_id` INT,
  `permission_id` INT,
  PRIMARY KEY (role_id, permission_id),
  FOREIGN KEY (role_id) REFERENCES roles(id),
  FOREIGN KEY (permission_id) REFERENCES permissions(id)
);

-- Admin permissions
INSERT INTO `role_permissions` (role_id, permission_id) VALUES
(1, 1), (1, 2), (1, 3), (1, 4), (1, 5);

-- HR permissions
INSERT INTO `role_permissions` (role_id, permission_id) VALUES
(2, 1), (2, 2), (2, 3), (2, 5);

-- Manager permissions
INSERT INTO `role_permissions` (role_id, permission_id) VALUES
(3, 1), (3, 3);

-- Employee permissions
INSERT INTO `role_permissions` (role_id, permission_id) VALUES
(4, 3);