<?php

namespace App\ExportMaps;

use App\ExportMaps\Contracts\ExportMapType;
use App\Traits\ExportMapImageColumns;
use Illuminate\Database\Eloquent\Builder;
use Mtc\MercuryDataModels\VehicleOffer;

class OfferExportMap implements ExportMapType
{
    use ExportMapImageColumns;

    public const NON_QUERYABLE_FIELDS = [
        'features.name',
        'specs.description',
        'equipment.description',
        'custom1',
        'custom2',
        'custom3',
        'custom4',
        'custom5',
        'custom6',
        'description_plain',
        'key_features',
        'standard_spec',
        'technical_spec',
        'empty',
        'site_url',
    ];

    public function name(): string
    {
        return 'Offers';
    }

    public function columns(bool $onlyEnabledIntegrations = false): array
    {
        return [
            'uuid' => 'Unique Identifier',
            'name' => 'Name',
            'slug' => 'Slug',
            'vin' => 'VIN',
            'published' => 'Published',
            'featured' => 'Featured',
            'type' => 'Type',
            'vehicle_type' => 'Vehicle Type',
            'derivative' => 'Derivative',
            'make.name' => 'Make',
            'model.name' => 'Model',
            'fuelType.name' => 'Fuel Type',
            'transmission.name' => 'Transmission',
            'bodyStyle.name' => 'Body Style',
            'dealership.name' => 'Dealership Name',
            'franchise.name' => 'Franchise Name',
            'offerType.name' => 'Offer Type',
            'price' => 'Price',
            'full_price' => 'Full Price',
            'deposit' => 'Deposit',
            'monthly_price' => 'Monthly Price',
            'engine_size_cc' => 'Engine Size (cc)',
            'colour' => 'Colour',
            'mpg' => 'MPG',
            'co2' => 'CO2',
            'battery_range' => '[EV] Battery Range',
            'battery_capacity_kwh' => '[EV] Battery Capacity (kWh)',
            'battery_usable_capacity_kwh' => '[EV] Battery Usable Capacity (kWh)',
            'battery_charge_time' => '[EV] Battery Charge Time',
            'battery_quick_charge_time' => '[EV] Battery Quick Charge Time',
            'battery_quick_charge_level' => '[EV] Battery Level at End of Quick Charge',
            'trim' => 'Trim',
            'description' => 'Description',
            'description_plain' => 'Description (Plain Text)',
            'youtube_video' => 'YouTube Video',
            'label' => 'Label',
            'excerpt' => 'Excerpt',
            'image_count' => 'Image Count',
            ...$this->getImageColumns(),
            'features.name' => 'Features',
            'specs.description' => 'Specs',
            'equipment.description' => 'Equipment',
            'cap_id' => 'CAP ID',
            'auto_trader_id' => 'AutoTrader ID',
            'dealership_id' => 'Dealership ID',
            'key_features' => 'Key Features',
            'standard_spec' => 'Standard Spec',
            'technical_spec' => 'Technical Spec',
            'custom1' => '[Custom] - Mapping Rules Field 1',
            'custom2' => '[Custom] - Mapping Rules Field 2',
            'custom3' => '[Custom] - Mapping Rules Field 3',
            'custom4' => '[Custom] - Mapping Rules Field 4',
            'custom5' => '[Custom] - Mapping Rules Field 5',
            'custom6' => '[Custom] - Mapping Rules Field 6',
            'empty' => 'Empty value',
            'created_at' => 'Created at',
            'updated_at' => 'Updated at',
            'stock_provider' => 'Stock Provider',
            'published_at' => 'Published At',
            'unpublished_at' => 'Unpublished At',
            'new_car_type' => 'New Car Type',
            't_and_cs' => 'Terms and Conditions',
            'footnote' => 'Footnote',
            'cta_button1_label' => 'CTA Button 1 Label',
            'cta_button1_url' => 'CTA Button 1 URL',
            'cta_button2_label' => 'CTA Button 2 Label',
            'cta_button2_url' => 'CTA Button 2 URL',
            'motor_check_id' => 'Motor Check ID',
            'drivetrain.name' => 'Drivetrain',
            'dealership.address1' => 'Dealership Address 1',
            'dealership.address2' => 'Dealership Address 2',
            'dealership.city' => 'Dealership City',
            'dealership.county' => 'Dealership County',
            'dealership.postcode' => 'Dealership Postcode',
            'dealership.email' => 'Dealership Email',
            'dealership.contact_no' => 'Dealership Phone',
            'dealership.country' => 'Dealership Country',
            'site_url' => 'Site URL',
        ];
    }

    public function queryableColumns(bool $onlyEnabledIntegrations = false): array
    {
        return array_diff_key(
            $this->columns($onlyEnabledIntegrations),
            array_flip(array_merge(self::NON_QUERYABLE_FIELDS, $this->getImageNonQueryableFields()))
        );
    }

    public function query(): Builder
    {
        return VehicleOffer::query();
    }
}
