-- ========================================================
-- Clock Reminder Notification Configuration
-- Company: PT Satya Abadi Pharma (Company ID = 8)
-- ========================================================

SET @company_id = 8;
SET @modified_by = 1;
SET @owner = 1;

-- ========================================================
-- 1. MAIN SWITCH - Enable/Disable All Clock Reminders
-- ========================================================
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'clock_reminder_enabled', 'true', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'true', modified = NOW(), modified_by = @modified_by;

-- ========================================================
-- 2. CLOCK IN REMINDER SETTINGS
-- ========================================================
-- Enable clock in reminder
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'clock_in_reminder_enabled', 'true', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'true', modified = NOW(), modified_by = @modified_by;

-- Minutes before shift start (30 minutes before)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'clock_in_reminder_minutes_before', '30', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = '30', modified = NOW(), modified_by = @modified_by;

-- Work days: 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday (Weekdays only)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'clock_in_reminder_days', '[1,2,3,4,5]', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = '[1,2,3,4,5]', modified = NOW(), modified_by = @modified_by;

-- ========================================================
-- 3. CLOCK OUT REMINDER SETTINGS
-- ========================================================
-- Enable clock out reminder
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'clock_out_reminder_enabled', 'true', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'true', modified = NOW(), modified_by = @modified_by;

-- Minutes before shift end (30 minutes before)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'clock_out_reminder_minutes_before', '30', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = '30', modified = NOW(), modified_by = @modified_by;

-- Work days: 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'clock_out_reminder_days', '[1,2,3,4,5]', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = '[1,2,3,4,5]', modified = NOW(), modified_by = @modified_by;

-- ========================================================
-- 4. MISSED CLOCK IN ALERT SETTINGS
-- ========================================================
-- Enable missed clock in alert
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'missed_clock_in_enabled', 'true', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'true', modified = NOW(), modified_by = @modified_by;

-- Minutes after shift start to trigger alert (60 minutes)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'missed_clock_in_minutes_after', '60', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = '60', modified = NOW(), modified_by = @modified_by;

-- ========================================================
-- 5. LATE ARRIVAL ALERT SETTINGS
-- ========================================================
-- Enable late arrival alert
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'late_arrival_enabled', 'true', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'true', modified = NOW(), modified_by = @modified_by;

-- Late threshold in minutes (15 minutes)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'late_arrival_threshold_minutes', '15', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = '15', modified = NOW(), modified_by = @modified_by;

-- ========================================================
-- 6. OVERTIME WARNING SETTINGS (DISABLED)
-- ========================================================
-- Overtime warning disabled by default (enable if needed)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'overtime_warning_enabled', 'false', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'false', modified = NOW(), modified_by = @modified_by;

INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'overtime_warning_hours_before', '2', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = '2', modified = NOW(), modified_by = @modified_by;

-- ========================================================
-- 7. RECIPIENT SETTINGS
-- ========================================================
-- Notify employee themselves
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'notify_employee', 'true', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'true', modified = NOW(), modified_by = @modified_by;

-- Notify supervisor
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'notify_supervisor', 'true', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'true', modified = NOW(), modified_by = @modified_by;

-- Notify HR (disabled by default)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'notify_hr', 'false', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'false', modified = NOW(), modified_by = @modified_by;

-- ========================================================
-- 8. CHANNEL SETTINGS
-- ========================================================
-- Send via system notification (bell icon)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'send_system_notification', 'true', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'true', modified = NOW(), modified_by = @modified_by;

-- Send via email (disabled by default)
INSERT INTO companysettings (company_id, `key`, value, creation, modified, modified_by, owner)
VALUES (@company_id, 'send_email', 'false', NOW(), NOW(), @modified_by, @owner)
ON DUPLICATE KEY UPDATE value = 'false', modified = NOW(), modified_by = @modified_by;

-- ========================================================
-- VERIFIKASI - Lihat semua setting yang sudah dibuat
-- ========================================================
SELECT 
    id,
    company_id,
    `key`,
    value,
    creation,
    modified
FROM companysettings
WHERE company_id = @company_id
AND (
    `key` LIKE 'clock_%' 
    OR `key` LIKE 'missed_%' 
    OR `key` LIKE 'late_%' 
    OR `key` LIKE 'overtime_%' 
    OR `key` LIKE 'notify_%' 
    OR `key` LIKE 'send_%'
)
ORDER BY `key`;

-- ========================================================
-- KONFIGURASI SELESAI!
-- ========================================================
-- Scheduler akan otomatis berjalan setiap 5 menit
-- Notifikasi akan muncul di bell icon notification
-- Restart server jika diperlukan
