<?php
namespace Database\Seeders;

use App\Models\Brand;
use App\Models\Category;
use App\Models\Product;
use Illuminate\Database\Seeder;

class ProductSeeder extends Seeder
{
    public function run(): void
    {
        $cat = fn(string $slug) => Category::where('slug', $slug)->value('id');
        $brand = fn(string $slug) => Brand::where('slug', $slug)->value('id');

        $products = [
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => $brand('angoalimentos'),
                'name' => 'Açúcar Amarelo Mangolê 1kg',
                'price' => 450.00, 'original_price' => 520.00,
                'badge' => 'Promoção', 'badge_color' => 'red',
                'is_active' => true, 'featured' => true, 'sort_order' => 1,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => $brand('nutriangola'),
                'name' => 'Arroz Agulha Nutriangola 5kg',
                'price' => 2350.00,
                'is_active' => true, 'featured' => true, 'sort_order' => 2,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => $brand('angoalimentos'),
                'name' => 'Arroz Agulha Angoalimentos 10kg',
                'price' => 4300.00, 'original_price' => 4800.00,
                'badge' => 'Económico', 'badge_color' => 'green',
                'is_active' => true, 'featured' => false, 'sort_order' => 3,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => $brand('sodiba'),
                'name' => 'Farinha de Trigo SODIBA 1kg',
                'price' => 380.00,
                'is_active' => true, 'featured' => true, 'sort_order' => 4,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => null,
                'name' => 'Farinha de Mandioca Mangolê 1kg',
                'price' => 320.00,
                'is_active' => true, 'featured' => false, 'sort_order' => 5,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => $brand('nutriangola'),
                'name' => 'Feijão Mauve Nutriangola 500g',
                'price' => 650.00,
                'is_active' => true, 'featured' => false, 'sort_order' => 6,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => null,
                'name' => 'Feijão Mulatinho Mangolê 1kg',
                'price' => 890.00,
                'is_active' => true, 'featured' => false, 'sort_order' => 7,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => null,
                'name' => 'Milho Pilado Mangolê 5kg',
                'price' => 1200.00,
                'is_active' => true, 'featured' => true, 'sort_order' => 8,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => null,
                'name' => 'Fuba de Milho Mangolê 3kg',
                'price' => 780.00,
                'is_active' => true, 'featured' => false, 'sort_order' => 9,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => $brand('púnica'),
                'name' => 'Óleo de Palma Púnica 1L',
                'price' => 1100.00,
                'is_active' => true, 'featured' => true, 'sort_order' => 10,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => $brand('púnica'),
                'name' => 'Azeite Virgem Extra Púnica 500ml',
                'price' => 2450.00,
                'is_active' => true, 'featured' => false, 'sort_order' => 11,
            ],
            [
                'category_id' => $cat('alimentar'),
                'brand_id' => null,
                'name' => 'Óleo Alimentar Mangolê 2L',
                'price' => 1450.00, 'original_price' => 1700.00,
                'badge' => 'Promoção', 'badge_color' => 'red',
                'is_active' => true, 'featured' => true, 'sort_order' => 12,
            ],
            [
                'category_id' => $cat('azeites-e-oleos'),
                'brand_id' => $brand('boa-mesa'),
                'name' => 'Azeite Tempero Boa Mesa 0.5L Plástico',
                'price' => 850.00,
                'image' => 'images/products/azeite_tempero_BoaMesa - Plastico 0.5L.png',
                'is_active' => true, 'featured' => true, 'sort_order' => 13,
            ],
            [
                'category_id' => $cat('azeites-e-oleos'),
                'brand_id' => $brand('boa-mesa'),
                'name' => 'Azeite Tempero Boa Mesa 1L Vidro',
                'price' => 1450.00,
                'image' => 'images/products/azeite_tempero_BoaMesa - Vidro1L.png',
                'is_active' => true, 'featured' => true, 'sort_order' => 14,
            ],
            [
                'category_id' => $cat('azeites-e-oleos'),
                'brand_id' => $brand('boa-mesa'),
                'name' => 'Azeite Tempero Boa Mesa 3L Plástico',
                'price' => 3200.00,
                'image' => 'images/products/azeite_tempero_BoaMesa - Plastico 3L.png',
                'is_active' => true, 'featured' => true, 'sort_order' => 15,
            ],
            [
                'category_id' => $cat('azeites-e-oleos'),
                'brand_id' => $brand('boa-mesa'),
                'name' => 'Azeite Tempero Boa Mesa 5L Plástico',
                'price' => 4900.00,
                'image' => 'images/products/azeite_tempro_BoaMesa-Plastico 5L.png',
                'is_active' => true, 'featured' => true, 'sort_order' => 16,
            ],
            [
                'category_id' => $cat('azeites-e-oleos'),
                'brand_id' => $brand('boa-mesa'),
                'name' => 'Azeite Tempero Boa Mesa 500ml Lata',
                'price' => 950.00,
                'image' => 'images/products/azeite_tempero__boa_mesa_lata_500ml-min.png',
                'is_active' => true, 'featured' => true, 'sort_order' => 17,
            ],
        ];

        foreach ($products as $data) {
            $data['description'] = 'Descrição de ' . lcfirst($data['name']) . '. Produto de qualidade disponível nas lojas Mangolê.';
            Product::firstOrCreate(
                ['slug' => str($data['name'])->slug()],
                $data
            );
        }
    }
}
