<?php

use App\Models\Mongo;

function getCONFIG($file){
    $config = (object) Mongo::table('tb_config')->where('config_type',$file)->first();
    return $config;
}


function setCONFIG($file,$varname,$value){
    $config = Mongo::table('tb_config')->where('config_type',$file)->first();
    if($config){
        $config[$varname] = $value;
        Mongo::table('tb_config')->where('config_type',$file)->update($config);
    }else{
        $confignew['config_type'] = $file;
        $confignew[$varname] = $value;
        Mongo::table('tb_config')->insert($confignew);
    }
}


function configTYPE($type,$key){
    $config = getCONFIG($type);
    if(isset($config->$key)){
        $val = $config->$key;
    }else{
        $val = "";
    }
    return $val;
}

function get_config_scope(){
    $status = false;
    try {
        $is_python = (object) Mongo::table('tb_lumina')->where('id', 1)->first();
        if(isset($is_python->python)){
            $status = $is_python->python;
        }
    } catch(Exception $e) {}
    return $status;
}

function get_key_config($key, $filename){
    $val = '';
    $data = (object) Mongo::table('tb_lumina')->where('id', 1)->first();
    if(isset($data->{$key})){
        $val = $data->{$key};
    }
    return $val;
}
