<?php

namespace App\Http\Controllers\BridgingBPJS;

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

class RujukanController extends BpjsController
{
    protected $bpjs;

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

    //--------------------------------- CARI RUJUKAN ----------------------------//
    public function RujukanPcare($noRujukan)
    {
        $endpoint = "Rujukan/" . $noRujukan;
        $rujukan = $this->bpjs->getRequest($endpoint);
        return $rujukan;
    }

    public function RujukanRs($noRujukan)
    {
        $endpoint = "Rujukan/RS/" . $noRujukan;
        $rujukanRs = $this->bpjs->getRequest($endpoint);
        return $rujukanRs;
    }

    public function PesertaPcare($noKartu)
    {
        $endpoint = "Rujukan/Peserta/" . $noKartu;
        $rujukanPeserta = $this->bpjs->getRequest($endpoint);
        return $rujukanPeserta;
    }

    public function PesertaRs($noKartu)
    {
        $endpoint = "Rujukan/RS/Peserta/" . $noKartu;
        $rujukanPesertaRs = $this->bpjs->getRequest($endpoint);
        return $rujukanPesertaRs;
    }

    public function PesertaListPcare($noKartu)
    {
        $endpoint = "Rujukan/List/Peserta/" . $noKartu;
        $rujukanList = $this->bpjs->getRequest($endpoint);
        return $rujukanList;
    }

    public function PesertaListRs($noKartu)
    {
        $endpoint = "Rujukan/RS/List/Peserta/" . $noKartu;
        $rujukanListRs = $this->bpjs->getRequest($endpoint);
        return $rujukanListRs;
    }

    //----------------------- Pembuatan Rujukan --------------------------------//
    // ---- VERSI 1.1 --------//
    public function DeleteRujukan(Request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Rujukan/delete";
        $rujukan = $this->bpjs->deleteRequest($endpoint, $data);
        return $rujukan;
    }

    public function InsertRujukan(Request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Rujukan/insert";
        $rujukan = $this->bpjs->postRequest($endpoint, $data);
        return $rujukan;
    }

    public function UpdateRujukan(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Rujukan/update";
        $rujukan = $this->bpjs->putRequest($endpoint, $data);
        return $rujukan;
    }

    // ---- VERSI 2.0 --------//
    public function InsertRujukanv2(Request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Rujukan/2.0/insert";
        $rujukan = $this->bpjs->postRequest($endpoint, $data);
        return $rujukan;
    }

    public function UpdateRujukanv2(request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Rujukan/2.0/Update";
        $rujukan = $this->bpjs->putRequest($endpoint, $data);
        return $rujukan;
    }

    //  --------------- rujukan khusus --------------//
    public function InsertRujukanKhusus(Request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Rujukan/Khusus/insert";
        $rujukan = $this->bpjs->postRequest($endpoint, $data);
        return $rujukan;
    }

    public function DeleteRujukanKhusus(Request $request)
    {
        $data = json_encode($request->all());
        $endpoint = "Rujukan/Khusus/delete";
        $rujukan = $this->bpjs->deleteRequest($endpoint, $data);
        return $rujukan;
    }

    public function ListRujukanKhusus($bulan, $tahun)
    {
        $endpoint = "Rujukan/Khusus/List/Bulan/" . $bulan . "/Tahun/" . $tahun;
        $rujukan = $this->bpjs->getRequest($endpoint);
        return $rujukan;
    }

    // ---------------- list spesialistik rujukan ----------------------//
    public function ListSpesialistik($kodePPK, $tgl)
    {
        $endpoint = "Rujukan/ListSpesialistik/PPKRujukan/" . $kodePPK . "/TglRujukan/" . $tgl;
        $rujukan = $this->bpjs->getRequest($endpoint);
        return $rujukan;
    }

    public function ListSarana($kodePPK)
    {
        $endpoint = "Rujukan/ListSarana/PPKRujukan/" . $kodePPK;
        $rujukan = $this->bpjs->getRequest($endpoint);
        return $rujukan;
    }
}
