<?php

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

class ChangeDischargeAuthName extends Migration
{
    protected $changeAuthNames = [
        '运输管理-卸货-服务商报表-查询' => '人事管理-卸货-装卸队报表-查询',
        '服务商' => '装卸队',
        '服务商-查询' => '装卸队-查询',
        '服务商-编辑' => '装卸队-编辑',
        '服务商-删除' => '装卸队-删除',
        '服务商-对账单-查询' => '装卸队-对账单-查询',
        '服务商-创建' => '装卸队-创建',
        '运输管理-卸货' => '人事管理-卸货',
        '运输管理-卸货-查询' => '人事管理-卸货-查询',
        '运输管理-卸货-编辑' => '人事管理-卸货-编辑',
        '运输管理-卸货-创建' => '人事管理-卸货-创建',
        '运输管理-卸货-删除' => '人事管理-卸货-删除',
        '运输管理-卸货-结算报表-查询' => '人事管理-卸货-结算报表-查询',
    ];

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        foreach ($this->changeAuthNames as $name => $changeName){
            Authority::query()->where('name',$name)->update([
                'name'=> $changeName,
                'alias_name'=> $changeName,
            ]);
        }

        Schema::table('discharge_tasks',function (Blueprint $table){
            $table->integer('warehouse_id')->comment('仓库')->default(null);
            $table->bigInteger('facilitator_id')->comment('装卸队')->default(null)->change();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        foreach ($this->changeAuthNames as $changeName => $name){
            Authority::query()->where('name',$name)->update([
                'name'=> $changeName,
                'alias_name'=> $changeName,
            ]);
        }

        Schema::table('discharge_tasks',function (Blueprint $table){
            $table->dropColumn('warehouse_id');
        });
    }
}
