<?php
declare(strict_types=1);

use Migrations\BaseMigration;

/**
 * Replaces the bundled SVG placeholder portraits with real photographic
 * portraits sourced from pravatar.cc (free service that serves real photos
 * curated from Unsplash). Square 400x400 deterministic by image number.
 *
 * If you want to use your own uploaded photos instead, edit the teacher in
 * /admin/teachers and set Photo path to e.g. `teachers/jane.jpg` (relative
 * to /webroot/img/). That value will overwrite the URL set here.
 */
class UpdateTeacherPhotosToReal extends BaseMigration
{
    public function up(): void
    {
        $map = [
            // Ishani Patel — warm-toned portrait, dark hair
            'ishani-patel' => 'https://i.pravatar.cc/400?img=44',
            // Marcus O'Shea — bearded man, studio-friendly
            'marcus-oshea' => 'https://i.pravatar.cc/400?img=68',
            // Lena Koh — knitting lead
            'lena-koh'     => 'https://i.pravatar.cc/400?img=47',
            // Tomás Rivera — advanced knitting
            'tomas-rivera' => 'https://i.pravatar.cc/400?img=60',
        ];

        foreach ($map as $slug => $url) {
            $this->execute(sprintf(
                "UPDATE teachers SET photo_path = '%s', modified = NOW() WHERE slug = '%s'",
                addslashes($url),
                addslashes($slug)
            ));
        }
    }

    public function down(): void
    {
        // Revert to the bundled SVG illustrations
        $map = [
            'ishani-patel' => 'teachers/ishani.svg',
            'marcus-oshea' => 'teachers/marcus.svg',
            'lena-koh'     => 'teachers/lena.svg',
            'tomas-rivera' => 'teachers/tomas.svg',
        ];
        foreach ($map as $slug => $path) {
            $this->execute(sprintf(
                "UPDATE teachers SET photo_path = '%s' WHERE slug = '%s'",
                addslashes($path),
                addslashes($slug)
            ));
        }
    }
}
