<?php

namespace helpers;

use Exception;
use objects\product_options_o;
use objects\products_o;

class xlvask_parser_undervognskylning extends xlvask_product_parser
{
    use xlvask_product_parser_t;

    public function __construct()
    {
        $this->setup('Undervognskylning'); // This is the name of Spot free product(s)
    }


    /**
     * @inheritDoc
     * @throws Exception
     */
    protected function parse(xlvask_wash_item $wash_item, xlvask_usage_log $xlvask_usage_log): products_o
    {
        // This means that we need to check the vehicle type and return the appropriate product.
        $primary_product_id = $xlvask_usage_log->getPrimaryItem()?->getProduct($xlvask_usage_log)?->id ?? null;
        // Get the available addons for the primary product
        $product_options = new product_options_o();
        if (empty($primary_product_id) || $product_options->isOptionAllowedOnType(21, $primary_product_id)) {
            return (new products_o())->select(21); // Undervognskylning product ID
        }
        // Throw an exception if the vehicle type is not supported
        throw new Exception('Unsupported vehicle type for Undervognskylning');
    }
}