<?php
namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;

use GuzzleHttp\Client;
use Illuminate\Http\Request;
use App\Model\MediaCategoryModel;

class ActiveCodeController extends Controller
{
    const SECRET_DOC = "http://ofc-secretdocs-svr.micro:50051";
    function index(Request $request){

        $data['doc_id'] = $request->doc_id; //1c734a3cdfb54533908324699958f5b4
        $data["category_id"] = $request->category_id;
        $data["appid"] = $request->appid;


        if ($request->doc_id){

            $client = new Client();
            $result = $client->get(self::SECRET_DOC."/api/license?doc_id=".$request->doc_id);

            $res = json_decode($result->getBody(),true);
            if (!isset($res["data"])){
                $data["activity_codes"] = [];
            }else{
                $data["activity_codes"] = $res["data"]["license"];
                $data["mobile"] = $res["data"]["mobile"];
            }
        }else{
            $data["activity_codes"] = [];
        }

        return view('admin.active_code.list',$data);
    }

}
