<?php

namespace modules\selfserve\traits;
require_once WD . '/modules/selfserve/helpers/selfserve_lane_status.php';
require_once WD . '/modules/selfserve/classes/selfserve_lane.php';
use modules\selfserve\classes\selfserve_lane;
use modules\selfserve\helpers\selfserve_lane_status;

trait selfserve_lane_status_t
{
    /**
     * @enum selfserve_lane_status
     * @description The lane availability status, which can be one of the following values:
     * @values OCCUPIED, FAULT, AVAILABLE, MAINTENANCE, CLOSED, RESERVED
     * @var selfserve_lane_status $status
     */
    public selfserve_lane_status $status;

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

    /**
     * Set the current status of the self-serve lane
     * @param selfserve_lane_status $status The new status of the self-serve lane
     * @return selfserve_lane_status_t|selfserve_lane
     */
    public function setLaneStatus(selfserve_lane_status $status): self
    {
        $this->status = $status;
        $this->setLaneCache($this->id, self::CACHE_SELFSERVE_LANE_KEY_STATUS, $this->status);
        return $this;
    }
}