USE vault_display;

INSERT INTO playlists (id, name, description, type, is_active)
VALUES
(10, 'Out Of Hours Display', 'Default closed/out-of-hours display playlist.', 'campaign', 1)
ON DUPLICATE KEY UPDATE name = VALUES(name), description = VALUES(description), type = VALUES(type), is_active = VALUES(is_active);

INSERT INTO content_items
(title, content_type, html_content, layout_template, is_active)
SELECT
'Out Of Hours Notice',
'html',
'<div class="pricing-board matrix-emergency"><h1>Next Theme</h1><div class="line">We are currently closed</div><div class="line">Scan online for websites, branding, signage and marketing</div><div class="line">nexttheme.co.uk</div></div>',
'notice',
1
WHERE NOT EXISTS (
    SELECT 1 FROM content_items WHERE title = 'Out Of Hours Notice' LIMIT 1
);

SET @out_hours_content_id = (SELECT id FROM content_items WHERE title = 'Out Of Hours Notice' ORDER BY id ASC LIMIT 1);

INSERT INTO playlist_items
(playlist_id, content_id, sort_order, duration_seconds, priority, is_active)
SELECT 10, @out_hours_content_id, 1, 20, 0, 1
WHERE @out_hours_content_id IS NOT NULL
AND NOT EXISTS (
    SELECT 1 FROM playlist_items WHERE playlist_id = 10 AND content_id = @out_hours_content_id LIMIT 1
);

INSERT INTO settings (setting_key, setting_value)
VALUES
('out_of_hours_playlist_id', '10'),
('opening_hours_json', '{"mon":{"open":"09:00","close":"17:00","closed":false},"tue":{"open":"09:00","close":"17:00","closed":false},"wed":{"open":"09:00","close":"17:00","closed":false},"thu":{"open":"09:00","close":"17:00","closed":false},"fri":{"open":"09:00","close":"17:00","closed":false},"sat":{"open":"09:00","close":"14:00","closed":false},"sun":{"open":"09:00","close":"17:00","closed":true}}')
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value);
