<?php

namespace Database\Seeders;

use App\Models\Field;
use App\Models\FieldOption;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class ProductFieldsSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $data = [
            [
                'name' => 'product_name',
                'label' => 'Product Name',
                'placeholder' => 'Name*',
                'options' => [],
            ],
            [
                'name' => 'category',
                'label' => 'Category',
                'placeholder' => 'Select*',
                'options' => [], // Options stored in `categories` table
            ],
            [
                'name' => 'stock_location',
                'label' => 'Stock Location',
                'placeholder' => 'Select*',
                'options' => [], // Options stored in `countries` table
            ],
            [
                'name' => 'type',
                'label' => 'Type',
                'placeholder' => 'Select*',
                'options' => ['Buying', 'Selling',]
            ],
            [
                'name' => 'unit_type',
                'label' => 'Unit Type',
                'placeholder' => 'Select*',
                'options' => ['Gram', 'Millilitre']
            ],
            [
                'name' => 'size',
                'label' => 'Size',
                'placeholder' => 'Enter unit size',
                'options' => []
            ],
            [
                'name' => 'packing',
                'label' => "Packing (Unit's Per Case)",
                'placeholder' => 'Enter*',
                'options' => []
            ],
            [
                'name' => 'quantity',
                'label' => 'Quantity (Number of Cases)',
                'placeholder' => 'Enter*',
                'options' => []
            ],
            [
                'name' => 'best_before',
                'label' => 'Best Before (Optional)',
                'placeholder' => 'Enter*',
                'options' => []
            ],
            [
                'name' => 'currency',
                'label' => 'Currency',
                'placeholder' => 'Select*',
                'options' => []
            ],
            [
                'name' => 'price',
                'label' => 'Price (Enter price, or ask the buyer/seller to contact you to discuss price by selecting the checkbox)',
                'placeholder' => '$',
                'options' => []
            ],
            [
                'name' => 'contact_for_price',
                'label' => 'Ask buyer/seller to contact you to discuss price',
                'placeholder' => '',
                'options' => []
            ],
            [
                'name' => 'description',
                'label' => 'Description',
                'placeholder' => 'Tell about your product*',
                'options' => []
            ],
            [
                'name' => 'upload_images',
                'label' => 'Upload Images & Video',
                'placeholder' => '',
                'options' => []
            ],
        ];

        foreach ($data as $fieldData) {
            $field = Field::create([
                'name' => $fieldData['name'],
                'label' => $fieldData['label'],
                'placeholder' => $fieldData['placeholder'],
            ]);

            foreach ($fieldData['options'] as $option) {
                FieldOption::create([
                    'field_id' => $field->id,
                    'value' => $option,
                ]);
            }
        }
    }
}
