<?php

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

class CreateTableUserUpdate extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('usr_u', function (Blueprint $table) {
            $table->id();
            $table->string('uid', 5)->unique()->nullable();
            $table->boolean('edit_pen')->default(false)->nullable();
             $table->boolean('edit_direct_pv')->default(false)->nullable();
            $table->boolean('approve_credits')->default(false)->nullable();
            $table->boolean('approve_plcy')->default(false)->nullable();
            $table->boolean('approve_own_plcy')->default(false)->nullable();
            $table->boolean('approve_client')->default(false)->nullable();
            $table->boolean('disapprove')->default(false)->nullable();
            $table->timestamps();
        });

        $testData = array(
            [
                'uid' => '1',
                'edit_pen' => '1',
                'approve_plcy' => '1',
                'edit_pn' => '1',
                'disapprove' => '1',
            ]
        );

        foreach ($testData as $test) {
            $init = new UserUpdate();
            $init->uid = $test['uid'];
            $init->edit_pen = $test['edit_pen'];
            $init->approve_plcy = $test['approve_plcy'];
            $init->approve_own_plcy = $test['edit_pn'];
            $init->disapprove = $test['disapprove'];
            $init->save();
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('usr_u');
    }
}
