<?php

declare(strict_types=1);

namespace OCA\Mitgliederverwaltung\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
 * Migration: Add Juleica fields to mv_members.
 *
 * Adds juleica_nummer (varchar, nullable) and juleica_ablaufdatum (date, nullable)
 * for tracking youth leader card data.
 *
 * Part of Issue #160.
 */
class Version000016Date20260410000001 extends SimpleMigrationStep {

    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
        /** @var ISchemaWrapper $schema */
        $schema = $schemaClosure();

        if ($schema->hasTable('mv_members')) {
            $table = $schema->getTable('mv_members');

            if (!$table->hasColumn('juleica_nummer')) {
                $table->addColumn('juleica_nummer', Types::STRING, [
                    'notnull' => false,
                    'length' => 100,
                    'default' => null,
                ]);
            }

            if (!$table->hasColumn('juleica_ablaufdatum')) {
                $table->addColumn('juleica_ablaufdatum', Types::DATE, [
                    'notnull' => false,
                    'default' => null,
                ]);
            }

            return $schema;
        }

        return null;
    }
}
