<?php

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

class CreateVendorsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('vendors', function (Blueprint $table) {
            $table->id();
            $table->string('user_id', 255); // Foreign key referencing users table's user_id (VARCHAR)
            $table->string('store_name');
            $table->text('complete_address');
            $table->string('gstin', 15)->unique();
            $table->decimal('longitude', 10, 7);
            $table->decimal('latitude', 10, 7);
            $table->json('services'); // Stores vendor services in JSON format
            $table->string('pan', 10)->unique();
            $table->decimal('balance', 10, 2)->default(0.00);

            // Store images (allow multiple images for store)
            $table->string('store_adhar')->nullable();
            
            // Store documents (allow up to 4 documents)
            $table->string('store_documents')->nullable();
            
            // Store PAN card image
            $table->string('store_pancard')->nullable();
            
            // Store pictures (allow up to 4 images)
            $table->string('store_pictures')->nullable();
            
            // Store selfies (allow up to 4 images)
            $table->string('store_selfies')->nullable();
            
            // Store profile image (single image)
            $table->string('profile_image')->nullable();
            
            // Single column for online/offline status (1 for online, 0 for offline)
            $table->boolean('online_status')->default(0); // 0 is offline, 1 is online
            
            $table->enum('approval_status', ['pending', 'approved', 'rejected'])->default('pending'); // Approval status
            
            $table->integer('total_orders')->default(0); // Total orders the vendor has processed
            
            // Opening hours as a JSON field (for example: {"monday": "9:00 AM - 5:00 PM", "tuesday": "9:00 AM - 5:00 PM"})
            $table->json('opening_hours')->nullable();
            
            $table->timestamps();

            // Foreign key relationship
            $table->foreign('user_id')->references('user_id')->on('users')->onDelete('cascade');
        });
    }

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