<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Customer;
use App\Models\Product;
use App\Models\ProductCategory;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        // Create admin user
        User::create([
            'name' => 'Admin User',
            'email' => 'admin@waltonplaza.com',
            'password' => Hash::make('password'),
            'phone' => '01712345678',
            'role' => 'admin'
        ]);
        
        // Create sales user
        User::create([
            'name' => 'Sales Executive',
            'email' => 'sales@waltonplaza.com',
            'password' => Hash::make('password'),
            'phone' => '01787654321',
            'role' => 'sales'
        ]);
        
        // Create product categories
        $categories = [
            ['name' => 'Refrigerator'],
            ['name' => 'Television'],
            ['name' => 'Air Conditioner'],
            ['name' => 'Washing Machine'],
            ['name' => 'Microwave Oven'],
            ['name' => 'Smartphone'],
        ];
        
        foreach ($categories as $category) {
            ProductCategory::create($category);
        }
        
        // Create sample products
        $products = [
            [
                'code' => 'WP-001',
                'name' => 'Walton Refrigerator 350L',
                'model' => 'WR-350',
                'category_id' => 1,
                'brand' => 'Walton',
                'description' => '350L Double Door Refrigerator',
                'purchase_price' => 35000,
                'selling_price' => 42999,
                'installment_price' => 44999,
                'warranty_period' => 24,
                'stock_quantity' => 25,
                'minimum_stock' => 5,
            ],
            [
                'code' => 'WP-002',
                'name' => 'Walton LED TV 55"',
                'model' => 'WT-55',
                'category_id' => 2,
                'brand' => 'Walton',
                'description' => '55 inch Smart LED TV',
                'purchase_price' => 42000,
                'selling_price' => 52999,
                'installment_price' => 54999,
                'warranty_period' => 24,
                'stock_quantity' => 15,
                'minimum_stock' => 3,
            ],
            [
                'code' => 'WP-003',
                'name' => 'Walton AC 1.5 Ton',
                'model' => 'WA-15',
                'category_id' => 3,
                'brand' => 'Walton',
                'description' => '1.5 Ton Inverter AC',
                'purchase_price' => 50000,
                'selling_price' => 62999,
                'installment_price' => 64999,
                'warranty_period' => 36,
                'stock_quantity' => 10,
                'minimum_stock' => 2,
            ],
        ];
        
        foreach ($products as $product) {
            Product::create($product);
        }
        
        // Create sample customers
        $customers = [
            [
                'customer_code' => 'CUST-001',
                'name' => 'Rahim Ahmed',
                'phone' => '01711111111',
                'email' => 'rahim@email.com',
                'address' => '123/A, Mirpur, Dhaka',
                'customer_type' => 'installment',
                'credit_limit' => 100000,
                'outstanding_balance' => 0,
            ],
            [
                'customer_code' => 'CUST-002',
                'name' => 'Karim Uddin',
                'phone' => '01822222222',
                'email' => 'karim@email.com',
                'address' => '456/B, Uttara, Dhaka',
                'customer_type' => 'cash',
                'credit_limit' => 50000,
                'outstanding_balance' => 0,
            ],
            [
                'customer_code' => 'CUST-003',
                'name' => 'Sadia Akter',
                'phone' => '01933333333',
                'email' => 'sadia@email.com',
                'address' => '789/C, Dhanmondi, Dhaka',
                'customer_type' => 'installment',
                'credit_limit' => 150000,
                'outstanding_balance' => 0,
            ],
        ];
        
        foreach ($customers as $customer) {
            Customer::create($customer);
        }
        
        $this->command->info('Database seeded successfully!');
        $this->command->info('Admin Login: admin@waltonplaza.com / password');
        $this->command->info('Sales Login: sales@waltonplaza.com / password');
    }
}