-- Run once in phpMyAdmin for an existing DigiKinnect installation.
-- New installations importing sql/digikinnect.sql do not need this migration.

CREATE TABLE IF NOT EXISTS system_settings (
    setting_key VARCHAR(100) PRIMARY KEY,
    setting_value TEXT NULL,
    updated_at DATETIME NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT IGNORE INTO system_settings (setting_key, setting_value, updated_at) VALUES
('organization_name', 'DigiKinnect', NOW()),
('public_headline', 'Big adventures start with a little curiosity.', NOW()),
('public_intro', 'Find a class your child will love, sign up in a few easy steps, and get ready to learn, create, and make new friends.', NOW()),
('contact_email', '', NOW()),
('contact_phone', '', NOW()),
('footer_text', 'Made for curious kids and the grown-ups who cheer them on.', NOW()),
('brand_color', '#6652c7', NOW()),
('company_logo_path', '', NOW());

SET @logo_column_exists = (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'classes'
      AND COLUMN_NAME = 'logo_path'
);
SET @logo_column_sql = IF(
    @logo_column_exists = 0,
    'ALTER TABLE classes ADD COLUMN logo_path VARCHAR(255) NULL AFTER description',
    'SELECT 1'
);
PREPARE logo_column_statement FROM @logo_column_sql;
EXECUTE logo_column_statement;
DEALLOCATE PREPARE logo_column_statement;
