<?php

class ModelFutura extends Model
{

    /**
     * @var String
     */
    protected $tableName;

    /**
     * @var String
     */
    protected $className;


    public function __construct($registry, $className)
    {
        parent::__construct($registry);

        $this->load->helper('Ftr_sql');

    }

    public function insert($entity)
    {
        /*transforma todos os parametros publicos da classe em um array*/
        $arrayEntity = get_object_vars($entity);

        /*retira o campo auto_increment para fazer o insert*/
        $arrayEntity = array_slice($arrayEntity, 1, count($arrayEntity));

        $sqlInsert = Ftr_sql::generateInsert($this->tableName,
            array_keys($arrayEntity)
        );

        $this->db->executeSql($sqlInsert, array_values($arrayEntity));

        return $this->db->getLastId();
    }

    public function findAll(){

        $sqlSelect = Ftr_sql::generateSelect($this->tableName);

        $results = $this->db->executeSql($sqlSelect, []);

        if($results){

//            $this->autoload->load($this->className);
//
//            $class = new $this->className();

        }

        return false;
    }

}