-- =====================================================================
-- SEED DATA  -  ogzguwwq_kiosk
-- Safe starter rows so the system is usable immediately after install.
-- PIN hash and admin pass are SHA-256. Defaults:
--   admin login : admin / admin123   (CHANGE AFTER FIRST LOGIN)
--   demo employee EMP001 , PIN 1234
-- =====================================================================

SET sql_mode = '';

INSERT INTO departments (dept_code, dept_name, is_active, created_at) VALUES
('ADMIN', 'Administration', 1, NOW()),
('ICT',   'ICT / MIS',      1, NOW()),
('FAC',   'Faculty',        1, NOW())
ON DUPLICATE KEY UPDATE dept_name = VALUES(dept_name);

INSERT INTO schedules (sched_name, time_in, time_out, grace_minutes, break_minutes, is_active, created_at) VALUES
('Regular Office 8-5', '08:00:00', '17:00:00', 15, 60, 1, NOW());

-- admin / admin123  -> sha256
INSERT INTO admin_users (username, pass_hash, full_name, role, is_active, created_at) VALUES
('admin',
 SHA2('admin123', 256),
 'System Administrator',
 'ADMIN', 1, NOW())
ON DUPLICATE KEY UPDATE pass_hash = VALUES(pass_hash);

-- One kiosk device registered (Main Gate). kiosk_key is the shared secret.
INSERT INTO kiosks (kiosk_key, label, is_active, created_at) VALUES
('MAINGATE-7F3A9C2E', 'Main Gate', 1, NOW())
ON DUPLICATE KEY UPDATE label = VALUES(label);

-- Demo employee EMP001 with PIN 1234
INSERT INTO employees (emp_no, first_name, last_name, dept_id, position,
                       daily_rate, hourly_rate, schedule_id, is_active, created_at)
VALUES ('EMP001', 'Juan', 'Dela Cruz',
        (SELECT dept_id FROM departments WHERE dept_code='ICT' LIMIT 1),
        'IT Staff', 1000.00, 125.00,
        (SELECT schedule_id FROM schedules WHERE sched_name='Regular Office 8-5' LIMIT 1),
        1, NOW())
ON DUPLICATE KEY UPDATE first_name = VALUES(first_name);

INSERT INTO emp_pins (emp_id, pin_hash, is_active, created_at)
SELECT e.emp_id, SHA2('1234', 256), 1, NOW()
FROM employees e WHERE e.emp_no = 'EMP001'
AND NOT EXISTS (SELECT 1 FROM emp_pins p WHERE p.emp_id = e.emp_id AND p.is_active = 1);
