<?php

namespace Database\Seeders\Global;

use Illuminate\Database\Seeder;
use App\Models\ExportMapTemplate;

class EnquiryMaxExportMapTemplateSeed extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        ExportMapTemplate::updateOrCreate(
            [
                'title' => 'EnquiryMax',
            ],
            [
                'is_published' => true,
                'sales_channel' => null,
                'type' => 'vehicle',
                'columns' => [
                    "custom1",
                    "uuid",
                    "registration_number",
                    "make.name",
                    "model.name",
                    "model.name",
                    "derivative",
                    "bodyStyle.name",
                    "empty",
                    "cap_code",
                    "first_registration_date",
                    "empty",
                    "description",
                    "empty",
                    "engine_size_cc",
                    "colour",
                    "standardEquipment.description",
                    "fuelType.name",
                    "empty",
                    "image_1",
                    "image_2",
                    "image_3",
                    "image_4",
                    "image_5",
                    "image_6",
                    "image_7",
                    "image_8",
                    "image_9",
                    "image_10",
                    "image_11",
                    "image_12",
                    "image_13",
                    "image_14",
                    "image_15",
                    "image_16",
                    "image_17",
                    "image_18",
                    "image_19",
                    "image_20",
                    "empty",
                    "empty",
                    "site_url",
                    "odometer_mi",
                    "empty",
                    "empty",
                    "previous_owner_count",
                    "door_count",
                    "empty",
                    "optionalEquipment.description",
                    "price",
                    "empty",
                    "empty",
                    "empty",
                    "empty",
                    "transmission.name",
                    "trim",
                    "is_vat_applicable",
                    "type",
                    "empty",
                    "vin",
                    "empty",
                    "empty",
                ],
                'headers' => [
                    "Dealership",
                    "Stock No",
                    "RegNo",
                    "Make",
                    "Range",
                    "Model",
                    "Derivative",
                    "Body Style",
                    "Capacity",
                    "CapCode",
                    "Date of Reg.",
                    "Days In Stock",
                    "Description",
                    "Engine Number",
                    "Engine Size",
                    "Exterior Colour",
                    "Fitted Options",
                    "Fuel Type",
                    "GlassID",
                    "Image1",
                    "Image2",
                    "Image3",
                    "Image4",
                    "Image5",
                    "Image6",
                    "Image7",
                    "Image8",
                    "Image9",
                    "Image10",
                    "Image11",
                    "Image12",
                    "Image13",
                    "Image14",
                    "Image15",
                    "Image16",
                    "Image17",
                    "Image18",
                    "Image19",
                    "Image20",
                    "Interior Colour",
                    "Last Service",
                    "Link",
                    "Mileage",
                    "MOT Expiry",
                    "Next Service",
                    "No Of Owners",
                    "No. of Doors",
                    "Notes",
                    "Optional Extras",
                    "Price",
                    "PurchasePrice",
                    "ReconditioningCost",
                    "SIV",
                    "Stock Type",
                    "Transmission",
                    "Trim",
                    "VAT Qualifying",
                    "Vehicle Type",
                    "VehicleCode",
                    "VIN No",
                    "Warranty Expiry",
                    "Warranty Type",
                ],
                'mapping_rules' => [
                    // Column A (Dealership): fixed site name for every exported row.
                    // SITE_NAME is a placeholder to be replaced per tenant with their eMAX site name.
                    [
                        "when" => [
                            "field" => "uuid",
                            "op" => "is_not_empty",
                            "value" => null,
                        ],
                        "then" => [
                            [
                                "action" => "set",
                                "target" => "custom1",
                                "value" => "SITE_NAME",
                            ],
                        ],
                    ],
                    // VAT Qualifying: convert stored Y/N into human-readable Yes/No.
                    [
                        "when" => [
                            "field" => "is_vat_applicable",
                            "op" => "eq",
                            "value" => "Y",
                        ],
                        "then" => [
                            [
                                "action" => "set",
                                "target" => "is_vat_applicable",
                                "value" => "Yes",
                            ],
                        ],
                    ],
                    [
                        "when" => [
                            "field" => "is_vat_applicable",
                            "op" => "eq",
                            "value" => "N",
                        ],
                        "then" => [
                            [
                                "action" => "set",
                                "target" => "is_vat_applicable",
                                "value" => "No",
                            ],
                        ],
                    ],
                ],
            ]
        );
    }
}
