<?php

namespace Hura8\Components\Media\Model;

use Hura8\Interfaces\AppResponse;
use Hura8\System\Model\aEntityBaseModel;
use Hura8\Interfaces\iEntityModel;
use Hura8\System\Url;


class ItemMediaModel extends aEntityBaseModel implements iEntityModel
{

    protected $item_type;
    protected $item_id;

    public function __construct(string $item_type = '', $item_id = 0) {
        parent::__construct('item-media');

        $this->item_type = $item_type;
        $this->item_id = $item_id;
    }


    protected function extendedFilterOptions() : array
    {
        return [
            // empty for now
        ];
    }


    protected function _buildQueryConditionExtend(array $filter_condition) : ?array
    {

        $catCondition   = [];
        $bind_types     = [];
        $bind_values    = [];

        if($this->item_type) {
            $catCondition[] = " AND `item_type` = ? ";
            $bind_types[] = 's';
            $bind_values[] = $this->item_type;
        }

        if($this->item_id) {
            $catCondition[] = " AND `item_id` = ? ";
            $bind_types[] = 'd';
            $bind_values[] = $this->item_id;
        }

        if(isset($filter_condition["item_type"]) && $filter_condition["item_type"]){
            $catCondition[] = " AND `item_type` = ? ";
            $bind_types[] = 's';
            $bind_values[] = $filter_condition["item_type"];
        }

        if(isset($filter_condition["item_id"]) && $filter_condition["item_id"]){
            $catCondition[] = " AND `item_id` = ? ";
            $bind_types[] = 's';
            $bind_values[] = $filter_condition["item_id"];
        }

        if(isset($filter_condition["file_type"]) && $filter_condition["file_type"]){
            $catCondition[] = " AND `file_type` = ? ";
            $bind_types[] = 's';
            $bind_values[] = $filter_condition["file_type"];
        }

        return array( join(" ", $catCondition), $bind_types, $bind_values);
    }




}
