<?php
/**
 * Seed the public changelog with the real build history of this site.
 *
 * Idempotent-ish: this TRUNCATEs and reloads, because the changelog is a
 * curated narrative, not accreting user data. Re-running gives a clean set.
 * (Contrast with seed-projects.php, which upserts to preserve ids.)
 *
 *   php api/cli/seed-changelog.php
 */

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../config.php';

// type, summary, detail (or null), 'YYYY-MM-DD HH:MM'
$entries = [
    ['added',   'Brand system established', 'Sumi-e direction — ink on washi paper, a single vermillion seal. Colour, type, and motion tokens.', '2026-07-21 16:40'],
    ['added',   'Homepage built', 'Ink hero with the signature writing itself, a typographic work index, and a full-bleed mission line.', '2026-07-22 09:15'],
    ['added',   'SeedProject cloned and wired', 'Astro frontend, PHP API, and MariaDB connected end to end.', '2026-07-22 12:05'],
    ['bug',     'Base schema failed to install', 'A migration declared a foreign key before the table it referenced existed.', '2026-07-22 12:40'],
    ['fixed',   'Schema install repaired', 'Added the standard foreign-key guard to the snapshot migration so tables load in any order.', '2026-07-22 12:42'],
    ['added',   'Navigation and brand mark', 'Header signature paired with the hanko seal; nav updated to Projects, Resume, About, Blog, Contact.', '2026-07-22 12:16'],
    ['added',   'Theme toggle', 'Light and dark, with an ink-reveal transition that spreads from the button you click.', '2026-07-22 12:49'],
    ['bug',     'Hero rendered paper-on-paper in light mode', 'A scoped colour override could not reach the already-resolved theme tokens.', '2026-07-22 12:58'],
    ['fixed',   'Ink surface scoping corrected', 'The dark hero now overrides the compiled colour tokens directly, in both themes.', '2026-07-22 12:58'],
    ['added',   'Full-page mobile menu', 'A curved reveal with the hamburger morphing into a close control.', '2026-07-22 13:25'],
    ['bug',     'Mobile menu clipped to the header', 'On inner pages the header\'s backdrop-blur trapped the fixed overlay to a thin strip.', '2026-07-22 13:44'],
    ['fixed',   'Menu portalled to the page root', 'The overlay now escapes the header entirely and covers the page identically everywhere.', '2026-07-23 12:45'],
    ['added',   'Animated 404 page', 'A playful full-screen 404, with a reduced-motion fallback and locally-hosted assets.', '2026-07-22 13:12'],
    ['added',   'React added as Astro islands', 'Interactive components hydrate only where used; the rest of the site stays static.', '2026-07-22 12:00'],
    ['added',   'Resume page', 'Experience, ventures, a grouped skills breakdown, education, and a downloadable PDF.', '2026-07-22 15:24'],
    ['added',   'Portraits with light/dark variants', 'A wardrobe swap — the right shot for each theme, graded into the palette.', '2026-07-22 15:51'],
    ['bug',     'A component import broke the build', 'Aliasing framer-motion to its successor created a circular module reference.', '2026-07-22 15:24'],
    ['fixed',   'Motion dependency resolved', 'Declared the real package directly instead of aliasing, ending the loop.', '2026-07-22 15:24'],
    ['added',   'Projects moved to the database', 'Per-project case-study pages generated from cja_projects at build time.', '2026-07-23 12:30'],
    ['added',   'Project filtering', 'Filter by category with an animated, shareable, deep-linkable transition.', '2026-07-23 12:44'],
    ['added',   'Contact form wired up', 'Real submissions stored in the database, with validation and spam protection.', '2026-07-23 12:14'],
    ['added',   'About page', 'The story from a Commodore 64 in 1988 to agentic AI today.', '2026-07-23 13:52'],
    ['fixed',   'About copy corrected', 'Separated learning to code (1988) from building software professionally (1999).', '2026-07-23 14:33'],
    ['added',   'Project galleries and social rail', 'A photo gallery with a lightbox, and a sticky Instagram rail beside each case study.', '2026-07-23 14:50'],
    ['added',   'This changelog', 'The site now documents its own evolution — fittingly, an agentic website that logs itself.', '2026-07-23 15:05'],
    ['updated', 'About headline tuned for search', 'Led with agentic AI and automation instead of the origin year — same story, better discoverability.', '2026-07-23 15:20'],
    ['added',   'Footer service links', 'Each service links straight to the contact form with the enquiry already selected.', '2026-07-23 15:35'],
    ['added',   'Services page', 'Automation, website design, and digital marketing — built for law firms and service businesses.', '2026-07-23 16:05'],
    ['updated', 'Contact form aligned to services', 'Enquiry types now mirror the three core services offered.', '2026-07-23 16:10'],
    ['updated', 'Navigation', 'Added Services to the main menu, front and centre.', '2026-07-23 16:12'],
    ['added',   'Private admin console', 'A secret-link sign-in to manage the site — pages, projects, and media — from one place.', '2026-07-23 22:30'],
    ['added',   'A site that edits itself', 'A confined AI agent takes a request, edits the relevant page, builds a preview, and publishes once you approve.', '2026-07-23 23:10'],
    ['added',   'Image and video uploads', 'Drop in a photo or clip; it is optimised on upload and placed straight into the page.', '2026-07-23 23:40'],
    ['added',   'Projects built from a brief', 'Describe a project and hand over the images — the agent writes the case study, groups the skills, and captions each shot.', '2026-07-24 00:05'],
    ['added',   'The Web Designer agent', 'A design agent for any page: give it a brief — instructions, a draft, images, video links — and it designs and publishes, working through a task queue.', '2026-07-24 00:40'],
    ['bug',     'Admin dropdowns unreadable in dark mode', 'The page and status menus rendered white-on-white when the admin was in dark mode.', '2026-07-24 02:34'],
    ['fixed',   'Admin dropdowns themed', 'Select menus now use the page palette in both light and dark, so the options are readable.', '2026-07-24 02:35'],
    ['fixed',   'Admin sign-in screen tidied', 'The login form and the signed-in panel no longer show at once; signing in now offers quick links to the Web Designer and projects.', '2026-07-24 02:36'],
    ['added',   'Changelog credits its authors', 'Every entry now shows who made the change — the site owner, or an agent that made it itself.', '2026-07-24 02:45'],
    ['added',   'The Web Designer logs its own work', 'Each change the design agent publishes is recorded here automatically, credited to the agent.', '2026-07-24 02:47'],
];

Db::execute('TRUNCATE TABLE cja_changelog');

// Each entry is [type, summary, detail, 'YYYY-MM-DD HH:MM', by?]. The 5th
// element (who made the change) is optional and defaults to the site owner.
$n = 0;
foreach ($entries as $e) {
    [$type, $summary, $detail, $at] = $e;
    $by = $e[4] ?? 'Carlos Arias';
    Db::insert('cja_changelog', [
        'type'      => $type,
        'summary'   => $summary,
        'detail'    => $detail,
        'actor'     => $by,
        'entry_at'  => $at . ':00',
        'published' => 1,
    ]);
    $n++;
}

echo "  seeded {$n} changelog entries\n";
