<?php

namespace App\Support;

use App\Cawangan;
use App\KadarUpah;
use App\Pampasan;
use App\Support\v1\GadaiV1 as Version1Gadai;

use App\Services\MasterServices;
use App\Support\v1\Penebusan;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request as HttpRequest;
use Illuminate\Support\Facades\Log;

class Tawarruq extends MasterServices
{
    protected $kodcaw;
    protected $cawangan_info;

    public function __construct(String $kodcaw){
        $this->kodcaw = $kodcaw;
        $this->cawangan_info  = parent::getInfoCawangan($kodcaw);
    }

    /* Start Gadaian */
    public function createGadai(HttpRequest $httpRequest){
        $gadai = new Version1Gadai($this->kodcaw,$this->cawangan_info);
        $response = $gadai->create($httpRequest);

        return $response;
    }

    public function createMarhunGadai($norujukan,HttpRequest $httpRequest){
        $gadai = new Version1Gadai($this->kodcaw,$this->cawangan_info);
        $response = $gadai->createMarhun($norujukan,$httpRequest);

        return $response;
    }

    public function updateGadaiMarhunKaunter($kodcaw, $norujukan, HttpRequest $request){
        $gadai = new Version1Gadai($this->kodcaw,$this->cawangan_info);
        $response = $gadai->updateAnsuranKaunter($this->kodcaw,$norujukan,$request);
        
        return $response;
    }

    public function updateJBGSemasa(HttpRequest $request){
        $gadai = new Version1Gadai($this->kodcaw,$this->cawangan_info);
        $response = $gadai->updateJBG($request);
        return $response;
    }

    public function getUpahSebenar($norujukan){
        $gadai = new Version1Gadai($this->kodcaw,$this->cawangan_info);
        $response = $gadai->kiraupahTawarruq($norujukan);

        return $response;
    }

    public function getUpahRebet($norujukan){
        $gadai = new Version1Gadai($this->kodcaw,$this->cawangan_info);
        $response = $gadai->kiraupahRebet($norujukan);
        
        return $response;
    }

    /* End Gadaian */

    /* Start Penebusan */

    public function tebusTawarruq($kodcaw,$norujukan,$jeniskeuntungan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->tebusTawarruq($this->kodcaw,$norujukan);

        return $response;
    }

    public function hargaTebusTawarruq($kodcaw,$norujukan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->hargaTebusTawarruq($this->kodcaw,$norujukan);

        return $response;
    }

    public function kiraUpahRebetSebenar($kodcaw,$norujukan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->kiraUpahRebetSebenar($this->kodcaw,$norujukan);

        return $response;
    }

    public function upahTawarruq($kodcaw,$norujukan,$jeniskeuntungan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->upahTawarruq($kodcaw,$norujukan,$jeniskeuntungan);

        return $response;
    }

    public function upahRebetTawarruq($kodcaw,$norujukan,$jeniskeuntungan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->upahRebetTawarruq($kodcaw,$norujukan,$jeniskeuntungan);

        return $response;
    }

    public function tebusSeparuhTawarruq($kodcaw,$norujukan,HttpRequest $request){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->tebusSeparuhTawarruq($this->kodcaw,$norujukan,$request);

        return $response;
    }

    public function tebusNotTawarruq($kodcaw,$norujukan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->tebusNotTawarruq($this->kodcaw,$norujukan);

        return $response;
    }

    public function hargaTebusNotTawarruq($kodcaw,$norujukan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->hargaTebusNotTawarruq($this->kodcaw,$norujukan);

        return $response;
    }

    public function kiraUpahNotTawarruq($kodcaw,$norujukan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->kiraUpahNotTawarruq($this->kodcaw,$norujukan);

        return $response;
    }

    public function upahNotTawarruq($kodcaw,$norujukan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->upahNotTawarruq($this->kodcaw,$norujukan);

        return $response;
    }

    public function tebusSeparuhNotTawarruq($kodcaw,$norujukan,HttpRequest $request){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->tebusSeparuhNotTawarruq($this->kodcaw,$norujukan,$request);

        return $response;
    }

    function rebet($kodcaw,$norujukan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->rebet($this->kodcaw,$norujukan);

        return $response;
    }

    function rebetselepastawarruq($kodcaw,$norujukan){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->rebetselepastawarruq($this->kodcaw,$norujukan);

        return $response;
    }

    public function tebusUpdate($kodcaw,$norujukan,HttpRequest $request){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->tebusUpdate($this->kodcaw,$norujukan,$request);

        return $response;
    }

    public function tebusUpdateAutoTawarruq($kodcaw,$norujukan,HttpRequest $request){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->transaksiPembiayaanSemula($this->kodcaw,$norujukan,$request);

        return $response;
    }

    public function kiraanupahTawarruqByTarikh($kodcaw,$norujukan,$tarikh){
        $tebus = new Penebusan($this->kodcaw,$this->cawangan_info);
        $response = $tebus->kiraupahTawarruqByTarikh($this->kodcaw,$norujukan,$tarikh);

        return $response;
    }

    /* End Penebusan */

    public function test(){
        echo 'tawarruq';
    }
}
