<?php

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

return new class extends Migration {
    public function up(): void
    {
        Schema::table('partner_account', function (Blueprint $table) {
                $table->integer('partner_id')->comment('')->change();
                $table->renameColumn('partner_id','user_id');
        });

        Schema::table('partner_commissions', function (Blueprint $table) {
            $table->string('order_no')->after('order_id')->comment('订单号');
            $table->integer('order_commission_id')->after('order_no')->comment('佣金来源');
            $table->integer('partner_id')->comment('')->change();
            $table->integer('status')->default(0)->comment('状态,0冻结,1已入账,2提现中,3取消,4被拒,5提现成功')->change();
            $table->renameColumn('partner_id','user_id');
            $table->integer('role')->after('partner_id')->comment('用户在此订单角色,1推荐人,2教练,3副教练,4客服');
            $table->integer('withdrawal_id')->nullable()->after('unfreeze_time')->comment('提现id');
        });

        Schema::table('partner_wallets', function (Blueprint $table) {
            $table->integer('partner_id')->comment('')->change();
            $table->renameColumn('partner_id','user_id');
        });

        Schema::table('partner_withdrawals', function (Blueprint $table) {
            $table->integer('partner_id')->comment('')->change();
            $table->renameColumn('partner_id','user_id');
        });

        Schema::table('partner_offline_orders', function (Blueprint $table) {
            $table->dropColumn('partner_id');
            $table->dropColumn('subcommission_type');
            $table->dropColumn('subcommission_val');
            $table->dropColumn('commission_amount');
        });
    }

    public function down(): void
    {
        Schema::table('partner_account', function (Blueprint $table) {
            $table->integer('user_id')->comment('合伙人id')->change();
            $table->renameColumn('user_id','partner_id');
        });

        Schema::table('partner_commissions', function (Blueprint $table) {
            $table->dropColumn('order_no');
            $table->dropColumn('order_commission_id');
            $table->integer('user_id')->comment('合伙人id')->change();
            $table->integer('status')->default(0)->comment('状态,0冻结,1已入账')->change();
            $table->renameColumn('user_id','partner_id');
            $table->dropColumn('role');
            $table->dropColumn('withdrawal_id');
        });

        Schema::table('partner_wallets', function (Blueprint $table) {
            $table->integer('user_id')->comment('合伙人id')->change();
            $table->renameColumn('user_id','partner_id');
        });

        Schema::table('partner_withdrawals', function (Blueprint $table) {
            $table->integer('user_id')->comment('合伙人id')->change();
            $table->renameColumn('user_id','partner_id');
        });

        Schema::table('partner_offline_orders', function (Blueprint $table) {
            $table->integer('user_id')->comment('合伙人id');
            $table->tinyInteger('subcommission_type')->nullable()->default('1')->comment('分佣类型,1为比例,2为固定金额');
            $table->decimal('subcommission_val',7,2)->nullable()->comment('分佣比例/固定金额金额');
            $table->decimal('commission_amount',7,2)->nullable()->comment('佣金');
        });

    }
};
