<?php

namespace App\Controllers;

class WrenchGeneralData extends BaseController
{
    public function __construct()
    {

    }

//    case 'preferences':
//                $in["action"] =  WRENCHBOARD_ACCOUNT_PREFERENCES;
//                //preferences // define('WRENCHBOARD_ACCOUNT_PREFERENCES',      11065);
//                break;


    public function signUpCountry(){
        $in["action"] = WRENCHBOARD_SIGNUP_COUNTRY;
        $endpoint = "SIGNUP_COUNTRY-";

        $out = $this->getCache($endpoint); // try find in cache
        if ( empty($out) || !is_array($out)){
            $ret = $this->wrenchboard->wrenchboard_api($in, $out);
            $out['internal_return'] = $ret;
            $this->saveCache($endpoint,$out,15000);
        }
        return $this->summaryReturnData($in,$out); //json_encode( $final_out );
    }

    public function usersPreferences(){

        $raw_json = file_get_contents('php://input');
        $in = json_decode($raw_json, true);

        $in["action"] = WRENCHBOARD_ACCOUNT_PREFERENCES;
        $endpoint = "USER_PREFERENCES";

        $out = $this->getCache($endpoint); // try find in cache
        if ( empty($out) || !is_array($out)){
            $ret = $this->wrenchboard->wrenchboard_api($in, $out);
            $out['internal_return'] = $ret;
            if ($ret >= 0 ){  // dont cache error
                $this->saveCache($endpoint,$out,25000);
            }
        }
        return $this->summaryReturnData($in,$out); //json_encode( $final_out );
    }

}