<?php

use Hyperf\Database\Schema\Blueprint;
use Hypervel\Database\Migrations\Migration;
use Hypervel\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('cooperative_members', function (Blueprint $table) {
            if (!Schema::hasColumn('cooperative_members', 'membership_type')) {
                $table->string('membership_type')->nullable()->after('role');
            }
            if (!Schema::hasColumn('cooperative_members', 'membership_level')) {
                $table->string('membership_level')->nullable()->after('membership_type');
            }
            if (!Schema::hasColumn('cooperative_members', 'officer_position')) {
                $table->string('officer_position')->nullable()->after('membership_level');
            }
            if (!Schema::hasColumn('cooperative_members', 'officer_level')) {
                $table->string('officer_level')->nullable()->after('officer_position');
            }
            if (!Schema::hasColumn('cooperative_members', 'concurrent_position')) {
                $table->string('concurrent_position')->nullable()->after('officer_level');
            }
            if (!Schema::hasColumn('cooperative_members', 'concurrent_level')) {
                $table->string('concurrent_level')->nullable()->after('concurrent_position');
            }
            if (!Schema::hasColumn('cooperative_members', 'cooperative_name_alt')) {
                $table->string('cooperative_name_alt')->nullable()->after('organization_id');
            }
            if (!Schema::hasColumn('cooperative_members', 'cooperative_position')) {
                $table->string('cooperative_position')->nullable()->after('cooperative_name_alt');
            }
            if (!Schema::hasColumn('cooperative_members', 'year_beginning')) {
                $table->string('year_beginning')->nullable()->after('cooperative_position');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('cooperative_members', function (Blueprint $table) {
             $table->dropColumn([
                'membership_type', 'membership_level', 'officer_position', 'officer_level',
                'concurrent_position', 'concurrent_level', 'cooperative_name_alt', 'cooperative_position', 'year_beginning'
            ]);
        });
    }
};
