<?php

namespace App\Http\Controllers\BridgingBPJS;

use App\Service\Bpjs\Bridging;
use Illuminate\Http\Request;

class SepController extends BpjsController
{
    protected $bpjs;

    public function __construct(\Illuminate\Http\Request $request)
    {
        parent::__construct();
        $this->request = $request;
        $this->bpjs = new Bridging($this->consid, $this->timestamp, $this->signature);
    }

    public function CariSep($noSep)
    {
        $endpoint = "SEP/" . $noSep;
        $sep = $this->bpjs->getRequest($endpoint);
        return $sep;
    }

    //-------------------------------------------- SEP versi 1.1 ---------------------------------------------///

    public function InsertSep(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/1.1/insert";
        $sep = $this->bpjs->postRequest($endpoint, $data);
        return $sep;
    }

    public function UpdateSep(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/1.1/Update";
        $sep = $this->bpjs->putRequest($endpoint, $data);
        return $sep;
    }

    public function DeleteSep(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/Delete";
        $sep = $this->bpjs->deleteRequest($endpoint, $data);
        return $sep;
    }


    //--------------------------------------- SEP versi 2.0 -----------------------------------------------------------//

    public function InsertSepV2(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/2.0/insert";
        $sep = $this->bpjs->postRequest($endpoint, $data);
        return $sep;
    }

    public function UpdateSepV2(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/2.0/update";
        $sep = $this->bpjs->putRequest($endpoint, $data);
        return $sep;
    }

    public function DeleteSepV2(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/2.0/delete";
        $sep = $this->bpjs->deleteRequest($endpoint, $data);
        return $sep;
    }

    // ----------------------------Potensi Suplesi Jasa Raharja----------------------------//
    public function SupJasaRaharja($noKartu, $tglPel)
    {
        $endpoint = "sep/JasaRaharja/Suplesi/" . $noKartu . "/tglPelayanan/" . $tglPel;
        $suplesi = $this->bpjs->getRequest($endpoint);
        return $suplesi;
    }

    public function DataIndukKecelakaan($noKartu)
    {
        $endpoint = "sep/KllInduk/List/" . $noKartu;
        $suplesi = $this->bpjs->getRequest($endpoint);
        return $suplesi;
    }

    // ----------------------------Approval Penjaminan SEP----------------------------//
    public function Pengajuan(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Sep/pengajuanSEP";
        $sep = $this->bpjs->postRequest($endpoint, $data);
        return $sep;
    }

    public function Approval(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Sep/aprovalSEP";
        $sep = $this->bpjs->postRequest($endpoint, $data);
        return $sep;
    }

    public function ListPersetujuanSEP($bulan,$tahun)
    {
        $endpoint = "Sep/persetujuanSEP/list/bulan/$bulan/tahun/$tahun";
        $suplesi = $this->bpjs->getRequest($endpoint);
        return $suplesi;
    }

    // ---------------------------- Update Tgl Pulang SEP ----------------------------//
    public function UpdateTglPulang(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Sep/updtglplg";
        $sep = $this->bpjs->putRequest($endpoint, $data);
        return $sep;
    }

    public function UpdateTglPulangv2(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/2.0/updtglplg";
        $sep = $this->bpjs->putRequest($endpoint, $data);
        return $sep;
    }

    public function ListDataUpdPersetujuanPulang($bulan,$tahun,$filter="")
    {
        $endpoint = "Sep/updtglplg/list/bulan/$bulan/tahun/$tahun/$filter";
        $suplesi = $this->bpjs->getRequest($endpoint);
        return $suplesi;
    }


    // ---------------------------- Integrasi SEP dan Inacbg ----------------------------//
    public function IntegrasiInacbg($noSep)
    {
        $endpoint = "sep/cbg/" . $noSep;
        $suplesi = $this->bpjs->getRequest($endpoint);
        return $suplesi;
    }

    // ---------------------------- SEP Internal ----------------------------//
    public function DataSepInternal($noSep)
    {
        $endpoint = "SEP/Internal/" . $noSep;
        $suplesi = $this->bpjs->getRequest($endpoint);
        return $suplesi;
    }

    public function DeleteSepInternal(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/Internal/delete";
        $sep = $this->bpjs->deleteRequest($endpoint, $data);
        return $sep;
    }

    //---------------------- FINGERPRINT ------------------------------------//
    public function GetFingerPrint($noKartu, $tglLayanan)
    {
        $endpoint = "SEP/FingerPrint/Peserta/$noKartu/TglPelayanan/$tglLayanan";
        $data = $this->bpjs->getRequest($endpoint);
        return $data;
    }

    public function GetListFingerPrint($tglLayanan)
    {
        $endpoint = "SEP/FingerPrint/List/Peserta/TglPelayanan/$tglLayanan";
        $data = $this->bpjs->getRequest($endpoint);
        return $data;
    }

    // ----------------------- RANDOM QUESTION ----------------------------//
    public function GetRandomQuestion($noKartu,$tglSep)
    {
        $endpoint = "SEP/FingerPrint/randomquestion/faskesterdaftar/nokapst/$noKartu/tglsep/$tglSep";
        $data = $this->bpjs->getRequest($endpoint);
        return $data;
    }

    public function PostRandomQuestion(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "SEP/FingerPrint/randomanswer";
        $sep = $this->bpjs->postRequest($endpoint, $data);
        return $sep;
    }



    public function Dokter()
    {
        $endpoint = "ref/dokter";
        $dokter = $this->bpjs->getRequest($endpoint);
        return $dokter;
    }

    public function Poli()
    {
        $endpoint = "ref/poli";
        $poli = $this->bpjs->getRequest($endpoint);
        return $poli;
    }
}
