<?php

namespace Hura8\Components\Staff\Model;

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

class StaffModel extends aEntityBaseModel
{

    public function __construct()
    {
        parent::__construct('staff');
        $this->tb_staff = $this->tb_entity;
    }


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


    public function getInfoByEmail($email) : ?array
    {
        $query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `email` = ? LIMIT 1 ", ['s'], [$email]) ;
        if( $item_info = $this->db->fetchAssoc($query)){
            return $this->formatItemInfo($item_info);
        }

        return null;
    }


    protected function _buildQueryConditionExtend(array $condition) : ?array
    {
        /*$condition = array(
            "letter" => "",
        );*/

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


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

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

}
