<?php
namespace front\factory;

class Scontainers
{
  public static function scontainer_details($scontainer_id)
  {
    global $mdb, $lang;

    $cacheHandler = new \Shared\Cache\CacheHandler();
    $cacheKey = "\front\factory\Scontainers::scontainer_details:$scontainer_id";

    $objectData = $cacheHandler->get($cacheKey);
    if ($objectData) {
      return unserialize($objectData);
    }

    $repository = new \Domain\Scontainers\ScontainersRepository($mdb);
    $langId = (string)($lang[0] ?? 'pl');
    $scontainer = $repository->detailsForLanguage((int)$scontainer_id, $langId);

    if (!is_array($scontainer)) {
      $scontainer = [
        'id' => (int)$scontainer_id,
        'status' => 0,
        'show_title' => 0,
        'languages' => [
          'lang_id' => $langId,
          'title' => '',
          'text' => '',
        ],
      ];
    }

    $cacheHandler->set($cacheKey, $scontainer);

    return $scontainer;
  }
}