<?php

namespace HelpGent\Database\Migrations\V224;

defined( 'ABSPATH' ) || exit;

use HelpGent\Database\Migrations\CreateDB;
use HelpGent\Database\Migrations\Migration as BaseMigration;
use HelpGent\Database\Migrations\Query;

class Migration extends BaseMigration {
    protected $migration_version = '2.2.4';

    protected bool $clean_up_data_after_migration = true;

    protected function skip_migration(): bool {
        return ! Query::table_exists( 'helpgent_guest_users' );
    }

    protected function before_start_migration(): void {
        ( new CreateDB() )->execute();
        UserDependedTableMigration::create_migration_helper_tables();
    }

    public function get_migration_tasks(): array {
        return [
            // User Migration
            [ 'callback' => [ UserMigration::class, 'migrate_guest_users' ] ],
            [ 'callback' => [ UserMigration::class, 'migrate_guest_user_meta' ] ],

            // User Depended Table Migration
            [ 'callback' => [ UserDependedTableMigration::class, 'migrate_responses' ] ],
            [ 'callback' => [ UserDependedTableMigration::class, 'migrate_messages' ] ],

            // Miscellaneous Migration
            [ 'callback' => [ MiscellaneousMigration::class, 'contact_info_migration' ] ],
            [ 'callback' => [ ConstraintsMigration::class, 'migrate_constraints' ] ],
        ];
    }

    protected function clean_up_data(): void {
        UserMigration::remove_old_tables();
        UserDependedTableMigration::clean_up();
    }
}