<?php

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

class CreateUserPayCreditsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_pay_credits', function (Blueprint $table) {
            $table->id();

            $table->unsignedInteger('user_id');

            $table->decimal('credit', 13, 2)->nullable();
            $table->decimal('old_credit_total', 13, 2)->nullable();
            $table->decimal('new_credit_total', 13, 2)->nullable();

            $table->text('message')->nullable();
    
            $table->unsignedTinyInteger('status')->index()->default(0);

            $table->unsignedInteger('shopping_order_id')->nullable();
            $table->timestamps();

            $table->foreign('user_id')
                ->references('id')
                ->on('users');

            $table->foreign('shopping_order_id')
                ->references('id')
                ->on('shopping_orders');

        });
    }

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