<?php

namespace App\FieldVisibility;

/**
 * Field/tab catalogue for the admin vehicle edit page.
 *
 * Keys match the `field-key` attributes applied to the matching elements in the
 * admin UI (backend-ui VehicleEdit/ViewIndex.vue). Tab keys are namespaced `tab_*`.
 *
 * Lockable fields are the ones the edit form validates as required (Vuelidate
 * `required` rules) plus the structural fields the form depends on. They can
 * never be hidden.
 */
class VehicleFieldCatalogue extends AbstractFieldCatalogue
{
    public const ENTITY = 'vehicle';

    public function entity(): string
    {
        return self::ENTITY;
    }

    public function groups(): array
    {
        return [
            ['key' => 'details', 'label' => 'Vehicle details'],
            ['key' => 'fuel', 'label' => 'Fuel source and consumption'],
            ['key' => 'price', 'label' => 'Price'],
            ['key' => 'content', 'label' => 'Content'],
            ['key' => 'tabs', 'label' => 'Tabs'],
        ];
    }

    public function fields(): array
    {
        return [
            // Vehicle details. Lockable keys are the ones UpdateVehicleRequest enforces as
            // mandatory (title, derivative, registration_number, make_id, model_id) — every
            // other field is nullable server-side and may be hidden.
            $this->field('title', 'Title', 'details', lockable: true),
            $this->field('type', 'Vehicle type', 'details'),
            $this->field('make_id', 'Make', 'details', lockable: true),
            $this->field('model_id', 'Model', 'details', lockable: true),
            $this->field('derivative', 'Derivative', 'details', lockable: true),
            $this->field('uuid', 'UUID', 'details'),
            $this->field('registration_number', 'Registration number', 'details', lockable: true),
            $this->field('first_registration_date', 'First registration date', 'details'),
            $this->field('colour', 'Colour', 'details'),
            $this->field('engine_size_cc', 'Engine size (cc)', 'details'),
            $this->field('odometer', 'Odometer', 'details'),
            $this->field('manufacture_year', 'Manufacture year', 'details'),
            $this->field('door_count', 'Doors', 'details'),
            $this->field('seats', 'Seats', 'details'),
            $this->field('transmission_id', 'Transmission', 'details'),
            $this->field('drivetrain_id', 'Drivetrain', 'details'),
            $this->field('body_style_id', 'Body style', 'details'),
            $this->field('previous_owner_count', 'Previous owners', 'details'),
            $this->field('vin', 'VIN', 'details'),
            $this->field('cap_id', 'Cap ID', 'details'),
            $this->field('cap_code', 'Cap Code', 'details'),
            $this->field('main_video_url', 'Video URL (main)', 'details'),
            $this->field('exterior_video_url', 'Exterior Video URL', 'details'),
            $this->field('interior_video_url', 'Interior Video URL', 'details'),
            $this->field('auto_trader_id', 'Auto Trader Vehicle ID', 'details'),

            // Fuel source and consumption
            $this->field('fuel_type_id', 'Fuel type', 'fuel'),
            $this->field('co2', 'CO2', 'fuel'),
            $this->field('mpg', 'MPG', 'fuel'),
            $this->field('battery_range', 'Battery range', 'fuel'),
            $this->field('battery_capacity_kwh', 'Battery Capacity (kWh)', 'fuel'),
            $this->field('battery_usable_capacity_kwh', 'Battery Usable Capacity (kWh)', 'fuel'),
            $this->field('battery_charge_time', 'Battery Charge Time (min)', 'fuel'),
            $this->field('battery_slow_charge_description', 'Battery Slow Charge Description', 'fuel'),
            $this->field('battery_quick_charge_time', 'Battery Quick Charge Time (min)', 'fuel'),
            $this->field('battery_quick_charge_start_level', 'Battery Quick Charge Start Level (%)', 'fuel'),
            $this->field('battery_quick_charge_level', 'Battery Quick Charge Level (%)', 'fuel'),
            $this->field('battery_quick_charge_description', 'Battery Quick Charge Description', 'fuel'),

            // Price
            $this->field('price', 'Price', 'price'),
            $this->field('original_price', 'Original Price', 'price'),
            $this->field('monthly_price', 'Monthly price', 'price'),
            $this->field('monthly_cost_type', 'Monthly price type', 'price'),
            $this->field('deposit', 'Deposit', 'price'),
            $this->field('rrp_price', 'RRP Price', 'price'),
            $this->field('admin_fee', 'Admin Fee', 'price'),

            // Content
            $this->field('attention_grabber', 'Attention grabber', 'content'),
            $this->field('trim', 'Trim', 'content'),

            // Tabs
            $this->field('tab_content', 'Content tab', 'tabs'),
            $this->field('tab_media', 'Media tab', 'tabs'),
            $this->field('tab_key_features', 'Key features tab', 'tabs'),
            $this->field('tab_tech_specs', 'Technical specs tab', 'tabs'),
            $this->field('tab_equipment', 'Equipment tab', 'tabs'),
            $this->field('tab_finance', 'Finance tab', 'tabs'),
            $this->field('tab_seo', 'SEO tab', 'tabs'),
            $this->field('tab_stats', 'Stats / Ad performance tab', 'tabs'),
        ];
    }
}
