<?php

namespace Hura8\Components\Product\Controller;

use Hura8\Components\Product\Model\ProductCategoryLanguageModel;
use Hura8\Components\Product\Model\ProductCategoryModel;
use Hura8\System\Controller\aCategoryBaseController;

class bProductCategoryController extends aCategoryBaseController
{

    static $image_folder = "media/category";

    protected  $objProductCategoryModel;


    public function __construct()
    {
        $this->objProductCategoryModel = new ProductCategoryModel();

        if(!$this->isDefaultLanguage()) {
            //$this->objProductCategoryLanguageModel->createTableLang();
            parent::__construct(
                $this->objProductCategoryModel,
                new ProductCategoryLanguageModel()
            );

        }else{
            parent::__construct(
                $this->objProductCategoryModel
            );
        }
    }


    protected function formatItemInfo(?array $info) : ?array
    {
        if(!$info) return null;

        if($info['icon']) $info['icon'] = STATIC_DOMAIN . "/" . static::$image_folder  . "/" . $info['icon'];

        return $info;
    }

    // get full info- basic with description
    public function getFullInfo($id): ?array
    {
        $info = $this->objProductCategoryModel->getFullInfo($id);

        if(!$info) return null;

        if($this->iEntityLanguageModel) {
            $item_language_info = $this->iEntityLanguageModel->getInfo($id);
            if($item_language_info) {
                return $this->formatItemInfo(array_merge($info, $item_language_info));
            }
        }

        return $this->formatItemInfo($info);
    }

}
