<?php
declare(strict_types=1);

use Migrations\BaseMigration;

/**
 * Sets photo_path on the four seeded teachers to point at the bundled
 * portrait SVGs in /webroot/img/teachers/.
 *
 * Idempotent: only updates rows whose photo_path is NULL or empty,
 * so a teacher who already has a real photo (uploaded via admin or set
 * manually) won't be overwritten.
 */
class AddTeacherPhotos extends BaseMigration
{
    public function up(): void
    {
        $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', modified = NOW() WHERE slug = '%s' AND (photo_path IS NULL OR photo_path = '')",
                addslashes($path),
                addslashes($slug)
            ));
        }
    }

    public function down(): void
    {
        $slugs = ['ishani-patel', 'marcus-oshea', 'lena-koh', 'tomas-rivera'];
        $list = "'" . implode("','", $slugs) . "'";
        $this->execute("UPDATE teachers SET photo_path = NULL WHERE slug IN ({$list}) AND photo_path LIKE 'teachers/%.svg'");
    }
}
