<?php
declare(strict_types=1);

use Migrations\BaseMigration;

class SeedOnboardingDemoData extends BaseMigration
{
    public function up(): void
    {
        $row = $this->fetchRow('SELECT COUNT(*) AS count FROM admin_users');
        if ($row !== false && (int)$row['count'] > 0) {
            return;
        }

        $this->execute(
            "INSERT INTO admin_users (email, password_hash, display_name, is_active, last_login_at, created, modified)
            VALUES ('admin@candlecraft.local', '\$2y\$12\$fiPrkBgAhEzkFbcZjR/KUedKqjizCb1hJ6cuGcr0GXLSsOWpTcdgu', 'CandleCraft Owner', 1, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
        );

        $this->execute(
            "INSERT INTO contact_messages (full_name, email, phone, interest_area, subject, message_body, status, admin_notes, consent_to_contact, reviewed_by_admin_user_id, created, modified)
            VALUES
            ('Maya Chen', 'maya@example.com', '0412000111', 'pottery', 'Trying pottery for the first time', 'I am looking for beginner-friendly pottery tutoring and would like to know how the first lesson works.', 'new', NULL, 1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
            ('Luca Singh', 'luca@example.com', NULL, 'both', 'Creative classes for after school', 'I am interested in both knitting and pottery and want to understand which option is best to begin with.', 'in_progress', 'Asked to follow up with next available intake details.', 1, 1, DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY), DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY)),
            ('Erin Walsh', 'erin@example.com', '0400999888', 'knitting', 'General question', 'Can adults join as complete beginners, or is this mainly for younger learners?', 'resolved', 'Resolved by email with orientation details.', 1, 1, DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 2 DAY), DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 2 DAY))"
        );
    }

    public function down(): void
    {
        $this->execute("DELETE FROM contact_messages WHERE email IN ('maya@example.com', 'luca@example.com', 'erin@example.com')");
        $this->execute("DELETE FROM admin_users WHERE email = 'admin@candlecraft.local'");
    }
}
