<?php

namespace Database\Seeders;

use App\Models\DeliveryPartner;
use App\Models\DeliveryPartnerApplication;
use App\Models\Product;
use App\Models\Vendor;
use App\Models\VendorApplication;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class TestDataSeeder extends Seeder
{
    public function run(): void
    {
        $app = VendorApplication::create([
            'business_name' => 'Khan General Store',
            'owner_name'    => 'Ali Khan',
            'phone'         => '03001111111',
            'cnic'          => '12345-1234567-1',
            'address'       => 'Main Bazaar, Batkhela',
            'locality'      => 'Batkhela',
            'category_id'   => 1,
            'business_type' => 'shop',
            'step1_phone_verified' => true,
            'step2_cnic_uploaded' => true,
            'step3_business_info_complete' => true,
            'step4_business_proof_uploaded' => true,
            'step5_selfie_uploaded' => true,
            'step6_bank_details_complete' => true,
            'current_step' => 7,
            'settlement_method' => 'easypaisa',
            'settlement_account_name' => 'Ali Khan',
            'settlement_account_number' => '03001111111',
            'status' => 'approved',
        ]);

        $vendor = Vendor::create([
            'application_id' => $app->id,
            'store_name'     => 'Khan General Store',
            'slug'           => 'khan-general-store',
            'phone'          => '03001111111',
            'address'        => 'Main Bazaar, Batkhela',
            'locality'       => 'Batkhela',
            'category_id'    => 1,
            'password'       => Hash::make('pass1234'),
            'tier'           => 'verified',
            'commission_rate'=> 10.00,
            'status'         => 'active',
            'uses_platform_delivery' => true,
            'settlement_method' => 'easypaisa',
            'settlement_account_name' => 'Ali Khan',
            'settlement_account_number' => '03001111111',
            'min_order_value' => 0,
        ]);

        Product::create([
            'vendor_id'      => $vendor->id,
            'category_id'    => 1,
            'subcategory_id' => 1,
            'name_en'        => 'Premium Basmati Rice 5kg',
            'name_ur'        => 'پریمیم باسمتی چاول',
            'slug'           => 'premium-basmati-rice',
            'sku'            => 'KHN-RICE-001',
            'price'          => 1500.00,
            'stock_quantity' => 50,
            'track_stock'    => true,
            'is_active'      => true,
            'unit'           => 'bag',
        ]);

        Product::create([
            'vendor_id'      => $vendor->id,
            'category_id'    => 1,
            'subcategory_id' => 2,
            'name_en'        => 'Sunflower Cooking Oil 5L',
            'name_ur'        => 'سورج مکھی کا تیل',
            'slug'           => 'sunflower-oil-5l',
            'sku'            => 'KHN-OIL-001',
            'price'          => 1800.00,
            'discount_price' => 1600.00,
            'stock_quantity' => 30,
            'track_stock'    => true,
            'is_active'      => true,
            'unit'           => 'bottle',
        ]);

        $dpApp = DeliveryPartnerApplication::create([
            'name'  => 'Hassan Driver',
            'phone' => '03002222222',
            'cnic'  => '12345-7654321-1',
            'vehicle_type' => 'motorcycle',
            'status' => 'approved',
            'current_step' => 8,
            'step1_phone_verified' => true,
            'step2_cnic_uploaded' => true,
            'step3_licence_uploaded' => true,
            'step4_vehicle_reg_uploaded' => true,
            'step5_selfie_uploaded' => true,
            'step6_vehicle_photo_uploaded' => true,
            'step7_guarantor_submitted' => true,
        ]);

        DeliveryPartner::create([
            'application_id' => $dpApp->id,
            'name'           => 'Hassan Driver',
            'phone'          => '03002222222',
            'cnic'           => '12345-7654321-1',
            'password'       => Hash::make('pass1234'),
            'vehicle_type'   => 'motorcycle',
            'is_online'      => true,
            'status'         => 'active',
            'acceptance_rate'=> 100.00,
            'completion_rate'=> 100.00,
            'payout_method'  => 'easypaisa',
            'payout_account' => '03002222222',
        ]);
    }
}
