<?php

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

return new class extends Migration
{
    public function up(): void
    {
        // 1. Update vendor_profiles with store timings and store logo/image
        Schema::table('vendor_profiles', function (Blueprint $table) {
            $table->string('opening_time')->default('10:00 AM')->after('longitude');
            $table->string('closing_time')->default('09:00 PM')->after('opening_time');
            $table->string('working_days')->default('Mon - Sat')->after('closing_time');
            $table->string('store_logo')->nullable()->after('working_days');
            $table->string('store_banner')->nullable()->after('store_logo');
        });

        // 2. Vendor Promotional Banners Table
        Schema::create('vendor_banners', function (Blueprint $table) {
            $table->id();
            $table->foreignId('vendor_id')->constrained('users')->cascadeOnDelete();
            $table->string('title');
            $table->string('image_url');
            $table->string('link_url')->nullable();
            $table->integer('sort_order')->default(0);
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        // 3. Vendor Store Offers & Deals Table
        Schema::create('vendor_offers', function (Blueprint $table) {
            $table->id();
            $table->foreignId('vendor_id')->constrained('users')->cascadeOnDelete();
            $table->string('title');
            $table->string('coupon_code')->nullable();
            $table->string('discount_type')->default('percentage'); // percentage, flat
            $table->decimal('discount_value', 10, 2)->default(0);
            $table->text('description')->nullable();
            $table->date('valid_until')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('vendor_offers');
        Schema::dropIfExists('vendor_banners');
        Schema::table('vendor_profiles', function (Blueprint $table) {
            $table->dropColumn([
                'opening_time',
                'closing_time',
                'working_days',
                'store_logo',
                'store_banner',
            ]);
        });
    }
};
