<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Inventory;
use App\Models\User;
use Illuminate\Support\Facades\Hash;

class PakistaniRestaurantInventorySeeder extends Seeder
{
    public function run(): void
    {
        // Get admin user or create one
        $admin = User::where('role', 'admin')->first();
        if (!$admin) {
            $admin = User::create([
                'name' => 'Admin User',
                'email' => 'admin@pos.com',
                'password' => Hash::make('password'),
                'role' => 'admin',
            ]);
        }

        $items = [
            // Rice & Grains
            ['item_name' => 'Basmati Rice', 'category' => 'Rice & Grains', 'item_unit' => 'kg', 'unit_price' => 450.00, 'quantity' => 100],
            ['item_name' => 'Regular Rice', 'category' => 'Rice & Grains', 'item_unit' => 'kg', 'unit_price' => 220.00, 'quantity' => 150],
            ['item_name' => 'Brown Rice', 'category' => 'Rice & Grains', 'item_unit' => 'kg', 'unit_price' => 380.00, 'quantity' => 50],
            ['item_name' => 'Wheat Flour', 'category' => 'Rice & Grains', 'item_unit' => 'kg', 'unit_price' => 120.00, 'quantity' => 200],
            ['item_name' => 'Maida (All Purpose Flour)', 'category' => 'Rice & Grains', 'item_unit' => 'kg', 'unit_price' => 130.00, 'quantity' => 100],

            // Spices & Masalas
            ['item_name' => 'Red Chili Powder', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 800.00, 'quantity' => 25],
            ['item_name' => 'Turmeric Powder', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 600.00, 'quantity' => 30],
            ['item_name' => 'Coriander Powder', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 700.00, 'quantity' => 20],
            ['item_name' => 'Cumin Seeds', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 1200.00, 'quantity' => 15],
            ['item_name' => 'Garam Masala', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 1500.00, 'quantity' => 10],
            ['item_name' => 'Black Pepper', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 1800.00, 'quantity' => 12],
            ['item_name' => 'Cardamom (Green)', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 3500.00, 'quantity' => 5],
            ['item_name' => 'Cardamom (Black)', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 2800.00, 'quantity' => 5],
            ['item_name' => 'Cinnamon Sticks', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 2200.00, 'quantity' => 8],
            ['item_name' => 'Bay Leaves', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 900.00, 'quantity' => 10],
            ['item_name' => 'Cloves', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 2500.00, 'quantity' => 6],
            ['item_name' => 'Fenugreek Seeds', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 1100.00, 'quantity' => 15],
            ['item_name' => 'Mustard Seeds', 'category' => 'Spices & Masalas', 'item_unit' => 'kg', 'unit_price' => 950.00, 'quantity' => 12],

            // Meat & Poultry
            ['item_name' => 'Chicken (Whole)', 'category' => 'Meat & Poultry', 'item_unit' => 'kg', 'unit_price' => 580.00, 'quantity' => 50],
            ['item_name' => 'Chicken Breast', 'category' => 'Meat & Poultry', 'item_unit' => 'kg', 'unit_price' => 750.00, 'quantity' => 30],
            ['item_name' => 'Beef Mince', 'category' => 'Meat & Poultry', 'item_unit' => 'kg', 'unit_price' => 1200.00, 'quantity' => 25],
            ['item_name' => 'Beef (Boneless)', 'category' => 'Meat & Poultry', 'item_unit' => 'kg', 'unit_price' => 1400.00, 'quantity' => 20],
            ['item_name' => 'Mutton (Goat)', 'category' => 'Meat & Poultry', 'item_unit' => 'kg', 'unit_price' => 1800.00, 'quantity' => 15],
            ['item_name' => 'Lamb Chops', 'category' => 'Meat & Poultry', 'item_unit' => 'kg', 'unit_price' => 2000.00, 'quantity' => 10],

            // Vegetables
            ['item_name' => 'Onions', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 180.00, 'quantity' => 200],
            ['item_name' => 'Tomatoes', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 250.00, 'quantity' => 150],
            ['item_name' => 'Potatoes', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 120.00, 'quantity' => 300],
            ['item_name' => 'Ginger', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 600.00, 'quantity' => 40],
            ['item_name' => 'Garlic', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 500.00, 'quantity' => 50],
            ['item_name' => 'Green Chilies', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 400.00, 'quantity' => 30],
            ['item_name' => 'Coriander Leaves', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 300.00, 'quantity' => 20],
            ['item_name' => 'Mint Leaves', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 350.00, 'quantity' => 15],
            ['item_name' => 'Bell Peppers', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 450.00, 'quantity' => 25],
            ['item_name' => 'Cauliflower', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 200.00, 'quantity' => 40],
            ['item_name' => 'Cabbage', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 150.00, 'quantity' => 35],
            ['item_name' => 'Okra (Bhindi)', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 350.00, 'quantity' => 20],
            ['item_name' => 'Eggplant (Brinjal)', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 280.00, 'quantity' => 25],
            ['item_name' => 'Spinach', 'category' => 'Vegetables', 'item_unit' => 'kg', 'unit_price' => 180.00, 'quantity' => 30],

            // Dairy Products
            ['item_name' => 'Full Cream Milk', 'category' => 'Dairy Products', 'item_unit' => 'liter', 'unit_price' => 180.00, 'quantity' => 100],
            ['item_name' => 'Yogurt (Dahi)', 'category' => 'Dairy Products', 'item_unit' => 'kg', 'unit_price' => 250.00, 'quantity' => 50],
            ['item_name' => 'Butter', 'category' => 'Dairy Products', 'item_unit' => 'kg', 'unit_price' => 1200.00, 'quantity' => 20],
            ['item_name' => 'Ghee (Clarified Butter)', 'category' => 'Dairy Products', 'item_unit' => 'kg', 'unit_price' => 1800.00, 'quantity' => 30],
            ['item_name' => 'Cream', 'category' => 'Dairy Products', 'item_unit' => 'liter', 'unit_price' => 450.00, 'quantity' => 25],
            ['item_name' => 'Paneer (Cottage Cheese)', 'category' => 'Dairy Products', 'item_unit' => 'kg', 'unit_price' => 800.00, 'quantity' => 15],

            // Oils & Cooking Mediums
            ['item_name' => 'Cooking Oil (Sunflower)', 'category' => 'Oils & Cooking Mediums', 'item_unit' => 'liter', 'unit_price' => 350.00, 'quantity' => 80],
            ['item_name' => 'Mustard Oil', 'category' => 'Oils & Cooking Mediums', 'item_unit' => 'liter', 'unit_price' => 400.00, 'quantity' => 40],
            ['item_name' => 'Desi Ghee', 'category' => 'Oils & Cooking Mediums', 'item_unit' => 'kg', 'unit_price' => 2200.00, 'quantity' => 25],

            // Pulses & Legumes
            ['item_name' => 'Red Lentils (Masoor Dal)', 'category' => 'Pulses & Legumes', 'item_unit' => 'kg', 'unit_price' => 450.00, 'quantity' => 50],
            ['item_name' => 'Yellow Lentils (Moong Dal)', 'category' => 'Pulses & Legumes', 'item_unit' => 'kg', 'unit_price' => 480.00, 'quantity' => 45],
            ['item_name' => 'Chickpeas (Chana)', 'category' => 'Pulses & Legumes', 'item_unit' => 'kg', 'unit_price' => 350.00, 'quantity' => 60],
            ['item_name' => 'Black Gram (Urad Dal)', 'category' => 'Pulses & Legumes', 'item_unit' => 'kg', 'unit_price' => 520.00, 'quantity' => 40],

            // Breads & Roti Ingredients
            ['item_name' => 'Naan Bread', 'category' => 'Breads & Roti', 'item_unit' => 'pcs', 'unit_price' => 25.00, 'quantity' => 200],
            ['item_name' => 'Roti (Chapati)', 'category' => 'Breads & Roti', 'item_unit' => 'pcs', 'unit_price' => 15.00, 'quantity' => 300],
            ['item_name' => 'Paratha', 'category' => 'Breads & Roti', 'item_unit' => 'pcs', 'unit_price' => 30.00, 'quantity' => 150],

            // Condiments & Sauces
            ['item_name' => 'Tomato Ketchup', 'category' => 'Condiments & Sauces', 'item_unit' => 'bottle', 'unit_price' => 180.00, 'quantity' => 50],
            ['item_name' => 'Green Chutney', 'category' => 'Condiments & Sauces', 'item_unit' => 'kg', 'unit_price' => 400.00, 'quantity' => 20],
            ['item_name' => 'Tamarind Chutney', 'category' => 'Condiments & Sauces', 'item_unit' => 'kg', 'unit_price' => 450.00, 'quantity' => 15],
            ['item_name' => 'Soy Sauce', 'category' => 'Condiments & Sauces', 'item_unit' => 'bottle', 'unit_price' => 250.00, 'quantity' => 30],
            ['item_name' => 'Vinegar', 'category' => 'Condiments & Sauces', 'item_unit' => 'liter', 'unit_price' => 200.00, 'quantity' => 25],

            // Dry Items
            ['item_name' => 'Salt', 'category' => 'Dry Items', 'item_unit' => 'kg', 'unit_price' => 80.00, 'quantity' => 100],
            ['item_name' => 'Sugar', 'category' => 'Dry Items', 'item_unit' => 'kg', 'unit_price' => 150.00, 'quantity' => 80],
            ['item_name' => 'Baking Soda', 'category' => 'Dry Items', 'item_unit' => 'kg', 'unit_price' => 120.00, 'quantity' => 20],
            ['item_name' => 'Yeast', 'category' => 'Dry Items', 'item_unit' => 'pack', 'unit_price' => 50.00, 'quantity' => 30],

            // Beverages
            ['item_name' => 'Black Tea Leaves', 'category' => 'Beverages', 'item_unit' => 'kg', 'unit_price' => 800.00, 'quantity' => 25],
            ['item_name' => 'Green Tea', 'category' => 'Beverages', 'item_unit' => 'pack', 'unit_price' => 450.00, 'quantity' => 20],
            ['item_name' => 'Lemon', 'category' => 'Beverages', 'item_unit' => 'kg', 'unit_price' => 300.00, 'quantity' => 40],
        ];

        foreach ($items as $item) {
            Inventory::create([
                'item_name' => $item['item_name'],
                'category' => $item['category'],
                'item_unit' => $item['item_unit'],
                'unit_price' => $item['unit_price'],
                'quantity' => $item['quantity'],
                'total_price' => $item['unit_price'] * $item['quantity'],
                'created_by' => $admin->id,
            ]);
        }

        $this->command->info('Successfully seeded ' . count($items) . ' Pakistani restaurant inventory items!');
    }
}

