<?php

namespace App\Http\Controllers\FCControllers;

use Illuminate\Http\Request;
use Auth;
use Log;
use Exception;
use App\Models\fcmodels\Country;
use App\Models\fcmodels\CountryRate;
use App\Models\fcmodels\Organization;
use App\Models\fcmodels\Wallet;
use App\Models\fcmodels\Shop;
use App\Models\fcmodels\Ivr;
class CountryController extends Controller
{
    //
    public function index()
    {
        if(Auth::check())
        {
            $id = Auth::user()->organization_id;
            $name = Auth::user()->name;
            $api_account = Auth::user()->api_account;
        }
        else{
            return abort('401');
        }
        $mycountries = CountryRate::where('shopId',$api_account)->with('rateCountry')->get();
        
        $wallet = Wallet::where('shopid',$api_account)->pluck('amount');
        return view('fcviews.countries.index',compact('wallet','mycountries'));
    }
    public function end(Request $request)
    {

//     //Set the response content type to application/json
//     header("Content-Type:application/json");
//     $resp = '{"Response":"OK"}';
//     //read incoming request
//     $postData = file_get_contents('php://input');
//     //log file
//     $filePath = "message.log";
//     //error log
//     $errorLog = "error.log";
//     //Parse payload to json
//     $unhcrdata = json_decode($postData,true);
//     //log
//     $file = fopen($filePath,"a");
//     //log incoming request
//     fwrite($file, $postData);
//     fwrite($file,"\r\n");
//     //log response and close file
//     fwrite($file,$resp);
//     fclose($file);

// 		$msisdn =  $unhcrdata['msisdn'];
// 		$shortCode =  $unhcrdata['shortCode'];
// 		$message =  $unhcrdata['message'];
// 		$dateReceived =  $unhcrdata['dateReceived'];
		
// 		////////////////////////use the object here//////////////////////////////
// 		///e.g.consume the data above into a file
// 		file_put_contents('test.log',$unhcrdata,FILE_APPEND);
        Log::info($request);
    }
}
