<?php

namespace Hura8\Components\Brand\Controller;

use Hura8\Components\Brand\Model\BrandLanguageModel;
use Hura8\Components\Brand\Model\BrandModel;
use Hura8\System\Controller\aEntityBaseController;


class bBrandController extends aEntityBaseController
{

    static $image_folder = "media/brand";

    static $resized_sizes = array(
        's' => ['width' => 200,] ,
    );

    /* @var BrandModel $objBrandModel */
    protected  $objBrandModel;
    /* @var BrandLanguageModel $objBrandLanguageModel */
    protected  $objBrandLanguageModel;
    protected $view_language = '';

    public function __construct()
    {
        $this->objBrandModel = new BrandModel();

        if(!$this->isDefaultLanguage()) {
            $this->objBrandLanguageModel = new BrandLanguageModel();
            //$this->objVideoLanguageModel->createTableLang();
            parent::__construct($this->objBrandModel, $this->objBrandLanguageModel);

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

    public function getInfoByUrl(string $band_index) : ?array
    {
        return $this->objBrandModel->getInfoByUrl($band_index);
    }

    protected function formatItemInList(array $item_info) : array
    {
        return $this->formatItemInfo($item_info);
    }


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

        $info = static::formatItemImage($item_info);

        $info['url'] = "/brand/".$info['brand_index'];

        return $info;
    }


    public static function formatItemImage(array $item_info) {
        $info = $item_info;

        foreach (static::$resized_sizes as $size => $value) {
            $info['image'][$size] = ($info['thumbnail']) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $info['thumbnail'] : '';
        }

        return $info;
    }


}
