<?php
declare(strict_types=1);

use Migrations\BaseMigration;

class CreateTeacherApplications extends BaseMigration
{
    public function change(): void
    {
        $t = $this->table('teacher_applications');
        $t
            ->addColumn('full_name', 'string', ['limit' => 150, 'null' => false])
            ->addColumn('email', 'string', ['limit' => 255, 'null' => false])
            ->addColumn('phone', 'string', ['limit' => 60, 'null' => true])
            ->addColumn('craft', 'string', ['limit' => 40, 'null' => false, 'comment' => 'pottery|knitting|both'])
            ->addColumn('years_experience', 'integer', ['null' => true])
            ->addColumn('specialties', 'string', ['limit' => 255, 'null' => true, 'comment' => 'comma-separated tags'])
            ->addColumn('portfolio_url', 'string', ['limit' => 500, 'null' => true])
            ->addColumn('about', 'text', ['null' => false, 'comment' => 'why they want to teach + relevant experience'])
            ->addColumn('availability_summary', 'text', ['null' => true])
            ->addColumn('status', 'string', ['limit' => 20, 'default' => 'new', 'null' => false, 'comment' => 'new|reviewing|approved|rejected'])
            ->addColumn('reviewed_by_admin_user_id', 'integer', ['null' => true])
            ->addColumn('promoted_teacher_id', 'integer', ['null' => true, 'comment' => 'set when application is approved + promoted'])
            ->addColumn('admin_notes', 'text', ['null' => true])
            ->addColumn('created', 'datetime', ['null' => false])
            ->addColumn('modified', 'datetime', ['null' => false])
            ->addForeignKey('reviewed_by_admin_user_id', 'admin_users', 'id', ['delete' => 'SET_NULL', 'update' => 'NO_ACTION'])
            ->addForeignKey('promoted_teacher_id', 'teachers', 'id', ['delete' => 'SET_NULL', 'update' => 'NO_ACTION'])
            ->addIndex(['status'])
            ->addIndex(['email'])
            ->create();
    }
}
