<?php

namespace App\Danoral;

use Illuminate\Database\Eloquent\Model;

use App\Danoral\Elementos\iElemento;


abstract class ModelBase extends Model implements iElemento
{
    protected static $SCHEMA = 'admin26';
    public static $ANO_ACTUAL = 2026;
    
    protected $tableName; 

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct(){
        date_default_timezone_set('America/Caracas');
    
        /*
        if(auth()->id() == 100100040000000001) {
            $this::$SCHEMA = 'admin24';
        }
            */
            
    }

    public function setSchema($schema) {
        $this->table = $schema .'.'. $this->tableName;
    }

    public function getSchema_anoActual() {
        return $this::$SCHEMA;
    }

    public function setSchema_ano($ano){
        switch($ano){
            case 2026:
                $schema = 'admin26';
                break;
            case 2025:
                $schema = 'admin25';
                break;
            case 2024:
                $schema = 'admin24';
                break;

            default:
                $schema = 'admin';
        }
        $this->table = $schema .'.'. $this->tableName;

        return $schema;
    }

    public function getSchema_ano($ano){
        switch($ano){
            case 2026:
                return 'admin26';
            case 2025:
                return 'admin25';
            case 2024:
                return 'admin24';

            default:
                return 'admin';
        }

    }

    public function getCN_jsys($ano, $mes){
        switch($ano){
            case 2025:
                return 'mysql_danoral25';
            case 2024:
                return 'mysql_danoral24';
            case 2023:
                return 'mysql_danoral23';
            case 2022:
                return 'mysql_danoral22';
            case 2021:
                if($mes < 10){
                    return 'mysql_danoral21';
                }else{
                    return 'mysql_danoral21d';
                }
            case 2020:
                return'mysql_danoral20';
        
            default:
                return 'mysql_danoral';
        }
    }


    public function getTable() {
        return $this->table;
    }


    public function getClassEL(){
        return '';
    }
    public function getIdEL(){
        return '';
    }
    public function getNameEL(){
        return '';
    }
    public function getCodEL(){
        return '';
    }
    public function getTypeEL(){
        return '';
    }
    public function getIconEL(){
        return 'search-outline';
    }

    public static function getSearch($strSearch){
        return null;
    }

    /**
     * devuelve el ano del id
     *  0123456
     * "100100240000000886"
     *        ||
     *        12  
     */
    public static function getYearID($id){
        return intval("20".substr($id, 6, 2)); 
    }

}
