<?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://192.168.10.111: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);

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

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

}
