<?php

namespace modules\selfserve\traits;

require_once WD . '/modules/selfserve/helpers/selfserve_lane_mode.php';
require_once WD . '/modules/selfserve/classes/selfserve_lane.php';
use modules\selfserve\classes\selfserve_lane;
use modules\selfserve\helpers\selfserve_lane_mode;

trait selfserve_lane_mode_t
{
    /**
     * @enum selfserve_lane_mode
     * @description The mode of the lane, which can be one of the following values:
     * @values MANUAL, AUTOMATIC
     * @var selfserve_lane_mode $mode
     */
    public selfserve_lane_mode $mode;

    /**
     * Get the current mode of the self-serve lane
     * @return selfserve_lane_mode The current mode of the self-serve lane
     */
    public function getLaneMode(): selfserve_lane_mode
    {
        $mode = $this->getLaneCache($this->id, self::CACHE_SELFSERVE_LANE_KEY_MODE, selfserve_lane_mode::class);
        if (!empty($mode)) {
            $this->mode = $mode;
        }
        else if (empty($this->mode)) {
            // If not found in cache, default to MANUAL
            $this->mode = selfserve_lane_mode::MANUAL;
            $this->setLaneCache($this->id, self::CACHE_SELFSERVE_LANE_KEY_MODE, $this->mode);
        }
        return $this->mode;
    }

    /**
     * Set the current mode of the self-serve lane
     * @param selfserve_lane_mode $mode
     * @return selfserve_lane_mode_t|selfserve_lane
     */
    public function setLaneMode(selfserve_lane_mode $mode): self
    {
        $this->mode = $mode;
        $this->setLaneCache($this->id, self::CACHE_SELFSERVE_LANE_KEY_MODE, $this->mode);
        return $this;
    }
}