<?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 einwilligung_datum column to members table for DSGVO consent tracking.
 *
 * Part of Issue #62 — DSGVO actions.
 */
class Version000008Date20260407000007 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('einwilligung_datum')) {
                $table->addColumn('einwilligung_datum', Types::DATE, [
                    'notnull' => false,
                    'default' => null,
                ]);
            }

            return $schema;
        }

        return null;
    }
}
