<?php

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

class CreateCarSalesTable extends Migration
{
    public function up()
    {
        Schema::create('car_sales', function (Blueprint $table) {
            $table->id();

            // Car Details
            $table->unsignedBigInteger('car_id');
            $table->date('date');
            $table->string('make');
            $table->string('model');
            $table->string('reg_year');
            $table->string('chassis_no');
            $table->string('engine_no');
            $table->string('registered_city');
            $table->string('transmission');
            $table->string('color');
            $table->string('registration_no');


            // seller_witness_name
            // seller_witness_cnic
            // buyer_witness_name
            // buyer_witness_cnic

            // Seller Info
            $table->string('seller_name');
            $table->string('seller_cnic');
            $table->string('seller_phone');
            $table->string('seller_address');

            $table->string('seller_witness_name');
            $table->string('seller_witness_cnic');

            // Buyer Info
            $table->string('buyer_name');
            $table->string('buyer_cnic');
            $table->string('buyer_phone');
            $table->string('buyer_address');

            $table->string('buyer_witness_name');
            $table->string('buyer_witness_cnic');

            // Other
            // Other
            $table->decimal('soled_price', 12);
            $table->decimal('received_amount', 10);
            $table->decimal('remaining_payment', 10);


            $table->timestamps();

            // Foreign key constraint
            $table->foreign('car_id')->references('id')->on('cars')->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::dropIfExists('car_sales');
    }
}
