<?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::create('pesanans', function (Blueprint $table) {
            $table->id();
            $table->string('kode_pesanan')->nullable();
            $table->string('nama_pemesan')->nullable();
            $table->enum('status_pesanan', [0, 1, 2])->default(1)->comment('0=takeaway,1=default,2=dinein');
            $table->dateTime('tanggal_pesanan')->nullable();
            $table->string('nomor_meja')->nullable();
            $table->string('keterangan_pesanan')->nullable();
            $table->string('total_pesanan')->nullable();
            $table->string('total_bayar')->nullable();
            $table->string('grand_total')->nullable();
            $table->string('nominal_bayar')->nullable();
            $table->string('nominal_kembali')->nullable();
            // diskon
            $table->foreignId('diskon_id')->nullable()->references('id')->on('diskons')->onUpdate('cascade')->onDelete('cascade');
            $table->string('nama_diskon')->nullable();
            $table->string('kode_diskon')->nullable();
            $table->string('diskon_persen')->nullable();
            $table->string('diskon_rupiah')->nullable();
            // kasir
            $table->foreignId('user_id')->nullable()->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');

            $table->unsignedBigInteger("updated_by")->nullable();
            $table->unsignedBigInteger("created_by")->nullable();
            $table->unsignedBigInteger("deleted_by")->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
    }

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