<?php

namespace Hura8\Components\Product\Model;

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

class ProductSpecGroupAttributeModel extends aEntityBaseModel
{

    protected $tb_product                = 'tb_product';
    protected $tb_product_spec           = 'tb_product_spec';
    protected $tb_product_spec_group     = 'tb_product_spec_group';
    protected $tb_product_spec_group_record    = 'tb_product_spec_group_record';


    public function __construct() {
        parent::__construct('product_spec_group_record');
    }


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


    public function getSpecGroupAttribute($group_id)
    {
        $query = $this->db->runQuery(
            "SELECT * FROM `".$this->tb_product_spec_group_record."` WHERE `group_id` = ? ORDER BY `ordering` ASC ",
            ['d'], [$group_id]
        );

        return $this->db->fetchAll($query);
    }



    protected function updateGroupAttributeCount($group_id) {
        $this->db->runQuery("UPDATE `".$this->tb_product_spec_group."` SET 
                                        `attribute_count` = (SELECT COUNT(*) FROM `".$this->tb_product_spec_group_record."` WHERE `group_id` = ? )
                                   WHERE `id` = ? LIMIT 1 ", ['d', 'd' ], [ $group_id, $group_id ]);
    }

    protected function buildQueryCondition(array $condition)
    {
        // TODO: Implement buildQueryCondition() method.
    }

    protected function buildOrderByCondition($order_by)
    {
        // TODO: Implement buildOrderByCondition() method.
    }


    protected function _buildQueryConditionExtend(array $extend_filter_conditions) : ?array
    {
        return null;
    }


}
