<?php

namespace App\Listeners;

use App\Crm\Config\DealerKitCrmConfig;
use App\Modules\Stock\DealerKit;

class AddDealerKitDealershipFields
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct(
        private readonly DealerKit $dealerKit,
        private readonly DealerKitCrmConfig $crmConfig,
    ) {
        //
    }

    /**
     * Handle the event.
     *
     * The dealer ID identifies the dealership within DealerKit for any
     * capability, so the field is surfaced when stock or CRM is enabled.
     *
     * @param object $event
     * @return array
     */
    public function handle($event)
    {
        if ($this->dealerKit->enabled() === false && $this->crmConfig->enabled() === false) {
            return [];
        }
        return $this->dealerKit->dealershipAdditionalDataFields();
    }
}
