<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('register_source', 30)->default('pc')->after('status');
            $table->string('last_login_source', 30)->nullable()->after('register_source');
            $table->string('wechat_openid', 64)->nullable()->after('last_login_source');
            $table->string('wechat_unionid', 64)->nullable()->after('wechat_openid');
            $table->string('mini_openid', 64)->nullable()->after('wechat_unionid');
        });

        Schema::table('orders', function (Blueprint $table) {
            $table->string('platform', 30)->default('pc')->after('status');
            $table->string('payment_channel', 30)->nullable()->after('platform');
            $table->string('payment_status', 30)->default('unpaid')->after('payment_channel');
            $table->string('device_type', 30)->nullable()->after('payment_status');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['register_source', 'last_login_source', 'wechat_openid', 'wechat_unionid', 'mini_openid']);
        });

        Schema::table('orders', function (Blueprint $table) {
            $table->dropColumn(['platform', 'payment_channel', 'payment_status', 'device_type']);
        });
    }
};
