<?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: Make geburtsdatum nullable in mv_members.
 *
 * Not every member record needs a birthday (e.g. Erziehungsberechtigte,
 * honorary members, or incomplete legacy data).
 *
 * Part of Issue #162.
 */
class Version000015Date20260410000000 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('geburtsdatum')) {
                $column = $table->getColumn('geburtsdatum');
                $column->setNotnull(false);
                $column->setDefault(null);
            }

            return $schema;
        }

        return null;
    }
}
