<?php

use App\Http\Controllers\Api\MemberController as ApiMemberController;
use Modules\Internal\Http\Controllers\Api\AuthController;
use Illuminate\Http\Request;
use Modules\Internal\Http\Controllers\Api\AppointmentController;
use Modules\Internal\Http\Controllers\Api\BenefitController;
use Modules\Internal\Http\Controllers\Api\CityController;
use Modules\Internal\Http\Controllers\Api\ClaimController;
use Modules\Internal\Http\Controllers\Api\ClaimRequestController;
use Modules\Internal\Http\Controllers\Api\RequestLogController;
use Modules\Internal\Http\Controllers\Api\RequestLogBenefitController;
use Modules\Internal\Http\Controllers\Api\RequestLogMedicineController;
use Modules\Internal\Http\Controllers\Api\CorporateBenefitController;
use Modules\Internal\Http\Controllers\Api\CorporateController;
use Modules\Internal\Http\Controllers\Api\CorporateFormulariumController;
use Modules\Internal\Http\Controllers\Api\CorporateMemberController;
use Modules\Internal\Http\Controllers\Api\CorporatePlanController;
use Modules\Internal\Http\Controllers\Api\CorporateServiceController;
use Modules\Internal\Http\Controllers\Api\DiagnosisController;
use Modules\Internal\Http\Controllers\Api\DiagnosisTemplateController;
use Modules\Internal\Http\Controllers\Api\DiagnosisExclusionController;
use Modules\Internal\Http\Controllers\Api\DistrictController;
use Modules\Internal\Http\Controllers\Api\DivisionController;
use Modules\Internal\Http\Controllers\Api\HospitalController;
use Modules\Internal\Http\Controllers\Api\DoctorController;
use Modules\Internal\Http\Controllers\Api\DoctorRatingController;
use Modules\Internal\Http\Controllers\Api\DrugController;
use Modules\Internal\Http\Controllers\Api\FormulariumController;
use Modules\Internal\Http\Controllers\Api\FormulariumTemplateController;
use Modules\Internal\Http\Controllers\Api\Linksehat\PaymentController;
use Modules\Internal\Http\Controllers\Api\LivechatController;
use Modules\Internal\Http\Controllers\Api\MemberController;
use Modules\Internal\Http\Controllers\Api\OptionController;
use Modules\Internal\Http\Controllers\Api\OrganizationController;
use Modules\Internal\Http\Controllers\Api\PlanController;
use Modules\Internal\Http\Controllers\Api\ProvinceController;
use Modules\Internal\Http\Controllers\Api\ServiceController;
use Modules\Internal\Http\Controllers\Api\PrescriptionController;
use Modules\Internal\Http\Controllers\Api\SpecialityController;
use Modules\Internal\Http\Controllers\Api\VillageController;
use Modules\Internal\Http\Controllers\Api\AuditTrailController;
use Modules\Internal\Http\Controllers\Api\DailyMonitoringController;
use Modules\Internal\Http\Controllers\Api\LaboratoriumResultController;
use Modules\Internal\Http\Controllers\Api\CorporateManageController;
use Modules\Internal\Http\Controllers\ClaimEncounterController;

// Report
use Modules\Internal\Http\Controllers\Api\ReportLogController;


/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/


Route::prefix('internal')->group(function () {

    Route::post('login', [AuthController::class, 'login'])->name('login');
    Route::post('register', [AuthController::class, 'register'])->name('register');
    Route::post('forget-password', [AuthController::class, 'forgetPassword'])->name('forget-password');
    Route::post('verify-email', [AuthController::class, 'verifyEmail'])->name('verify-email');

    Route::get('linksehat/payments', [PaymentController::class, 'index']);


    Route::middleware('auth:sanctum')->group(function () {

        Route::post('logout', [AuthController::class, 'logout'])->name('logout');
        Route::get('/user', function (Request $request) {
            return $request->user();
        });
        Route::put('reset-password', [AuthController::class, 'resetPassword'])->name('resetPassword');


        Route::resource('corporates', CorporateController::class);
        Route::get('corporates/import-document-example/{document_type}', [CorporateController::class, 'importDocumentExample']);
        Route::put('corporates/{corporate_id}/activation', [CorporateController::class, 'activation']);
        Route::post('corporates/{corporate_id}/import-plan-benefit', [CorporateController::class, 'importPlanBenefit']);
        Route::post('corporates/{corporate_id}/delete-import-plan-benefit', [CorporateController::class, 'deleteAllImportPlanBenefit']);
        Route::get('corporates/{corporate_id}/data-plan-benefit', [CorporateController::class, 'dataPlanBenefit']);
        Route::get('corporates/{corporate_id}/code', [CorporateController::class, 'corporateCode']);
        Route::get('corporates/{corporate_id}/payor_id', [CorporateController::class, 'corporatePayorId']);

        Route::get('corporates/{corporate_id}/corporate-plans', [CorporatePlanController::class, 'index']);
        Route::post('corporates/{corporate_id}/corporate-plans', [CorporatePlanController::class, 'store']);
        Route::get('corporates/{corporate_id}/corporate-plans/{id}/edit', [CorporatePlanController::class, 'edit']);
        Route::put('corporates/{corporate_id}/corporate-plans/{id}', [CorporatePlanController::class, 'update']);
        Route::post('corporates/{corporate_id}/corporate-plans/filter', [CorporatePlanController::class, 'filter']);
        Route::put('plans/{plan_id}/activation', [CorporatePlanController::class, 'activation']);

        Route::get('corporates/{corporate_id}/plans', [PlanController::class, 'index']);
        Route::post('corporates/{corporate_id}/plans/import', [PlanController::class, 'planImport']);

        Route::get('corporates/{corporate_id}/corporate-benefits', [CorporateBenefitController::class, 'index']);
        Route::post('corporates/{corporate_id}/corporate-benefits', [CorporateBenefitController::class, 'store']);
        Route::get('corporates/{corporate_id}/corporate-benefits/{id}/edit', [CorporateBenefitController::class, 'edit']);
        Route::put('corporates/{corporate_id}/corporate-benefits/{id}', [CorporateBenefitController::class, 'update']);
        Route::put('benefits/{benefit_id}/activation', [CorporateBenefitController::class, 'activation']);

        Route::get('corporates/{corporate_id}/benefits', [BenefitController::class, 'index']);
        Route::post('corporates/{corporate_id}/benefits/import', [BenefitController::class, 'memberBenefitImport']);

        Route::get('corporates/{corporate_id}/divisions', [DivisionController::class, 'index']);
        Route::post('corporates/{corporate_id}/divisions', [DivisionController::class, 'store']);
        Route::get('corporates/{corporate_id}/divisions/{id}/edit', [DivisionController::class, 'edit']);
        Route::put('corporates/{corporate_id}/divisions/{id}', [DivisionController::class, 'update']);

        Route::get('corporates/{corporate_id}/hospitals', [HospitalController::class, 'index']);
        Route::put('hospitals/{hospital_id}/activation', [HospitalController::class, 'activation']);
        Route::get('corporates/{corporate_id}/hospitals/data', [HospitalController::class, 'dataHospital']);
        Route::post('corporates/{corporate_id}/hospitals/save', [HospitalController::class, 'store']);
        Route::put('corporates/{corporate_id}/hospitals/{id}/edit', [HospitalController::class, 'update']);
        Route::get('corporates/hospitals/download-template', [HospitalController::class, 'downloadTemplate']);
        Route::post('corporates/{corporate_id}/hospitals/import', [HospitalController::class, 'import']);


        Route::get('corporates/{corporate_id}/members', [CorporateMemberController::class, 'index']);
        Route::get('corporates/{corporate_id}/members/list', [CorporateMemberController::class, 'generateMemberList']);
        Route::post('corporates/{corporate_id}/members/import', [CorporateMemberController::class, 'import']);
        Route::put('members/{member_id}/activation', [CorporateMemberController::class, 'activation']);
        Route::post('members/update', [CorporateMemberController::class, 'update']);


        Route::get('corporates/{corporate_id}/diagnosis', [DiagnosisExclusionController::class, 'listDiagnosis']);

        Route::get('corporates/{corporate_id}/diagnosis-exclusions', [DiagnosisExclusionController::class, 'index']);
        Route::get('corporates/{corporate_id}/diagnosis-exclusions/{id_exclusion}', [DiagnosisExclusionController::class, 'detilExclusion']);   // By Bagaskoro, get detil exclusion
        Route::post('corporates/{corporate_id}/diagnosis-exclusions/store', [DiagnosisExclusionController::class, 'storeExclusion']);
        Route::put('corporates/diagnosis-exclusions/update_activation', [DiagnosisExclusionController::class, 'updateActivation']);             // By Bagaskoro, edit status aktif
        Route::delete('diagnosis-exclusions/{id}', [DiagnosisExclusionController::class, 'destroy']);
        Route::post('corporates/{corporate_id}/diagnosis-exclusions/import', [DiagnosisExclusionController::class, 'import']);

        Route::get('corporates/{corporate_id}/services', [CorporateServiceController::class, 'index']);
        Route::put('corporates/{corporate_id}/services', [CorporateServiceController::class, 'update']);
        Route::get('corporates/{corporate_id}/services/{service_code}', [CorporateServiceController::class, 'corporateServiceIndex']);
        Route::put('corporates/{corporate_id}/services/{service_code}', [CorporateServiceController::class, 'corporateServiceUpdate']);
        Route::post('corporates/{corporate_id}/services/{service_code}/specialities', [CorporateServiceController::class, 'corporateServiceSpecialityUpdate']);
        Route::post('corporates/{corporate_id}/services/{service_code}/specialities-all', [CorporateServiceController::class, 'corporateServiceSpecialityAllUpdate']);
        Route::post('corporates/{corporate_id}/services/{service_code}/specialities/exclusion', [CorporateServiceController::class, 'storeExclusion']);

        Route::get('corporates/{corporate_id}/formulariums', [CorporateFormulariumController::class, 'index']);
        Route::get('corporates/{corporate_id}/formulariums/{formularium_id}', [CorporateFormulariumController::class, 'show']);
        Route::get('corporates/{corporate_id}/formulariums-create', [CorporateFormulariumController::class, 'create']);
        Route::post('corporates/{corporate_id}/formulariums', [CorporateFormulariumController::class, 'store']);
        Route::get('corporates/{corporate_id}/formulariums/list', [CorporateFormulariumController::class, 'generateFormulariumList']);
        Route::post('corporates/{corporate_id}/formulariums/import', [CorporateFormulariumController::class, 'import']);
        Route::put('corporates/{corporate_id}/formulariums-update-status/{id}', [CorporateFormulariumController::class, 'active']);
        Route::put('corporates/{corporate_id}/formulariums/{formularium_id}/{action}', [CorporateFormulariumController::class, 'updateStatus']);


        Route::controller(CorporateController::class)->group(function () {
            Route::post('add-files-doc', 'addFilesDoc');
            Route::post('get-files-doc', 'getFilesDoc');
            Route::post('update-status-files-doc', 'updateStatusFilesDoc');
        });

        // Route::get('corporates/{corporate_id}/diagnosis-exclusions', [DiagnosisExclusionController::class, 'index']);
        // Route::get('corporates/{corporate_id}/diagnosis-exclusions/import', [DiagnosisExclusionController::class, 'import']);

        // Audittrail
        Route::get('audittrail/{corporate_id}', [AuditTrailController::class, 'index']);

        Route::prefix('case_management')->group(function () {
            Route::get('memberlist', [DailyMonitoringController::class, 'GetMemberList']);
            Route::get('claimlist/{member_id}', [DailyMonitoringController::class, 'GetClaimList']);

            // Daily Monitoring
            Route::prefix('daily_monitoring')->group(function () {
                Route::get('detail/{claim_code}/list', [DailyMonitoringController::class, 'GetDetailMonitoringList']);
                Route::post('detail/{claim_code}/add', [DailyMonitoringController::class, 'AddDetailMonitoringList']);
                Route::post('detail/{claim_code}/add-request', [DailyMonitoringController::class, 'AddDetailMonitoringListRequestLog']);
                Route::post('detail/{claim_code}/update-status', [DailyMonitoringController::class, 'UpdateListRequestLog']);
            });

            // Laboratorium Result
            Route::prefix('laboratorium_result')->group(function () {
                Route::get('detail/{claim_code}/list', [LaboratoriumResultController::class, 'GetDetailLabResultList']);
                Route::post('detail/{claim_code}/add', [LaboratoriumResultController::class, 'AddDetailLabResultList']);
            });
        });

        Route::prefix('user_management')->group(function () {
            Route::get('/', [CorporateManageController::class, 'index']);
            Route::post('/', [CorporateManageController::class, 'store']);
            Route::post('/{id}', [CorporateManageController::class, 'update']);
            Route::post('/delete/{id}', [CorporateManageController::class, 'destroy']);
        });


        Route::get('master/diagnosis-template', [DiagnosisTemplateController::class, 'index']);
        Route::get('master/diagnosis-template/search', [DiagnosisTemplateController::class, 'search']);
        Route::post('master/diagnosis-template/store', [DiagnosisTemplateController::class, 'store']);
        Route::put('master/diagnosis-template/{id}/activation', [DiagnosisTemplateController::class, 'activation']);
        Route::get('master/diagnosis-template/{id}/edit', [DiagnosisTemplateController::class, 'edit']);
        Route::put('master/diagnosis-template/{id}/update', [DiagnosisTemplateController::class, 'update']);

        Route::get('master/formulariums/{formulariums_template_id}', [FormulariumController::class, 'index']);
        Route::post('master/formulariums/{formulariums_template_id}', [FormulariumController::class, 'store']);
        Route::post('master/formulariums/{formulariums_template_id}/import', [FormulariumController::class, 'import']);
        Route::get('master/formulariums/{formulariums_template_id}/list', [FormulariumController::class, 'generateFormulariumList']);

        Route::get('master/formularium-template', [FormulariumTemplateController::class, 'index']);
        Route::get('master/formularium-template/search', [FormulariumTemplateController::class, 'search']);
        Route::post('master/formularium-template/store', [FormulariumTemplateController::class, 'store']);
        Route::put('master/formularium-template/{id}/activation', [FormulariumTemplateController::class, 'activation']);
        Route::get('master/formularium-template/{id}/edit', [FormulariumTemplateController::class, 'edit']);
        Route::put('master/formularium-template/{id}/update', [FormulariumTemplateController::class, 'update']);

        Route::get('master/diagnosis/{diagnosis_template_id}', [DiagnosisController::class, 'index']);
        Route::get('master/diagnosis/{diagnosis_template_id}/search', [DiagnosisController::class, 'search']);
        Route::post('master/diagnosis/{diagnosis_template_id}/import', [DiagnosisController::class, 'import']);
        Route::get('master/diagnosis/{diagnosis_template_id}/list', [DiagnosisController::class, 'generateIcdList']);
        Route::put('master/diagnosis/{diagnosis_template_id}/activation', [DiagnosisController::class, 'activation']);

        Route::get('master/drugs', [DrugController::class, 'index']);
        Route::put('master/drugs/{drug_id}/activation', [DrugController::class, 'activation']);
        Route::get('master/drugs/download-template', [DrugController::class, 'downloadTemplate']);
        Route::post('master/drugs/import', [DrugController::class, 'import']);


        Route::get('members', [MemberController::class, 'index']);
        Route::get('members/{member_id}/benefits', [MemberController::class, 'benefits']);

        Route::post('claims/{claim_id}/encounters', [ClaimEncounterController::class, 'store']);
        Route::post('claims/{claim_id}/encounters/{encounter_id}/update', [ClaimEncounterController::class, 'update']);
        Route::post('claims/{claim_id}/set-final-encounter', [ClaimEncounterController::class, 'setFinalEncounter']);

        Route::get('claims', [ClaimController::class, 'index']);
        Route::post('claims/{id}/update-items', [ClaimController::class, 'updateItems'])->name('claim.update-items');
        Route::post('claims/{id}/update-diagnosis', [ClaimController::class, 'updateDiagnosis'])->name('claim.update-diagnosis');
        Route::post('claims/{id}/decline', [ClaimController::class, 'decline'])->name('claim.decline');
        Route::post('claims/{id}/approve', [ClaimController::class, 'approve'])->name('claim.approve');
        Route::post('claims/{id}/re-open', [ClaimController::class, 'reOpen'])->name('claim.re-open');

        Route::post('claims/{id}/carehistory', [ClaimController::class, 'storeHistoryCare']);
        Route::post('claims/carehistory/{id}/update', [ClaimController::class, 'updateHistoryCare']);
        Route::get('claims/carehistory/{id}', [ClaimController::class, 'showHistoryCare']);
        Route::post('claims/carehistory/approval', [ClaimController::class, 'approvalHistoryCare']);

        Route::post('claims', [ClaimController::class, 'store']);
        Route::get('claims/{id}', [ClaimController::class, 'show']);
        Route::put('claims/{id}', [ClaimController::class, 'update']);
        Route::get('claims/{id}/edit', [ClaimController::class, 'edit']);
        Route::post('check-limit', [ClaimController::class, 'checkLimit']);
        Route::get('claims/1/data-claim', [ClaimController::class, 'dataClaimReport']);
        Route::get('claims/detail/{id}', [ClaimController::class, 'getDetailClaims']);
        Route::post('claims/request-documents', [ClaimController::class, 'requestDocuments']);
        Route::get('claims/get-services/{id}', [ClaimController::class, 'getServices']);
        Route::post('claims/save-services', [ClaimController::class, 'saveServices']);
        Route::get('claims/{id}/benefit-configuration', [ClaimController::class, 'getBenefitConfiguration']);       // Bagaskoro, BSD 03 November 2023
        Route::put('claims/benefit-configuration/edit/{id}', [ClaimController::class, 'editBenefitConfiguration']); // Bagaskoro, BSD 03 November 2023

        Route::get('customer-service/request', [RequestLogController::class, 'index']);
        Route::post('customer-service/request', [RequestLogController::class, 'createNew']);
        Route::put('customer-service/request/{id}', [RequestLogController::class, 'update']);
        Route::get('customer-service/request/{id}', [RequestLogController::class, 'show']);
        Route::put('customer-service/request/delete/{id}', [RequestLogController::class, 'destroy']);
        Route::put('customer-service/request/final_log/{id}', [RequestLogController::class, 'deleteFinalLog']);
        Route::get('customer-service/request/{id}/download', [RequestLogController::class, 'generateRequestLog']);
        Route::post('customer-service/request/import', [RequestLogController::class, 'importRequestLog']);
        Route::get('customer-service/request/data', [RequestLogController::class, 'generateDataRequestLogExcel']);

        Route::post('customer-service/request/final-log', [RequestLogController::class, 'updateFinalLog']);
        
        // search diagnosis
        Route::get('diagnosis', [RequestLogController::class, 'diagnosis']);
        
        // insert benefit
        Route::post('customer-service/request/insert-benefit', [RequestLogBenefitController::class, 'store']);
        Route::delete('customer-service/request/benefit_data/{id}', [RequestLogBenefitController::class, 'destroy']);
        Route::put('customer-service/request/benefit_data/{id}', [RequestLogBenefitController::class, 'update']);
        
        // insert medicine
        Route::post('customer-service/request/medicine-data', [RequestLogMedicineController::class, 'store']);
        Route::delete('customer-service/request/medicine-data/{id}', [RequestLogMedicineController::class, 'destroy']);
        Route::put('customer-service/request/medicine-data/{id}', [RequestLogMedicineController::class, 'update']);
        
        Route::get('search-organizations', [OrganizationController::class, 'searchOrganization']);
        Route::get('search-specialities', [SpecialityController::class, 'searchSpeciality']);
        Route::resource('organizations', OrganizationController::class);
        Route::resource('appointments', AppointmentController::class);
        Route::get('live-chat/export', [LivechatController::class, 'export']);
        Route::resource('live-chat', LivechatController::class);
        Route::get('prescription', [PrescriptionController::class, 'index']);
        Route::get('prescription/{id}', [PrescriptionController::class, 'index']);
        Route::get('doctorrating', [DoctorRatingController::class, 'index']);
        Route::get('doctorrating/{id}', [PrescriptionController::class, 'index']);

        Route::resource('doctors', DoctorController::class);

        Route::post('generate-log/{member_id}', [CorporateMemberController::class, 'generateLog']);

        Route::get('send_card/{corporate_id}', [CorporateMemberController::class, 'sendAllECard']);
        Route::get('view_card/{member_id}', [CorporateMemberController::class, 'viewECard']);
        Route::controller(ClaimRequestController::class)->group(function () {
            Route::post('files-mcu', 'filesMcu');
        });


        Route::get('claim-requests', [ClaimRequestController::class, 'index'])->name('claim-requests.index');
        Route::get('claim-requests/list-member', [ClaimRequestController::class, 'getClaimMemberInfiniteScroll']);              // Bagaskoro, BSD 31 Oktober 2023
        Route::post('claim-requests/{id}/approve', [ClaimRequestController::class, 'approve'])->name('claim-requests.approve');
        Route::get('claim-requests/{id}', [ClaimRequestController::class, 'show'])->name('claim-requests.show');
        Route::post('claim-requests', [ClaimRequestController::class, 'createNew']);                                            // Bagaskoro, BSD 2 November 2023
        Route::put('claim-requests/{id}', [ClaimRequestController::class, 'update'])->name('claim-requests.update');
        Route::post('claim-requests/import', [ClaimRequestController::class, 'importClaim'])->name('claim-requests.importClaim');
        Route::get('claim-requests/detail/{id}', [ClaimRequestController::class, 'claimRequestDetail']);
        Route::post('claim-requests/{id}/invoice-files', [ClaimRequestController::class, 'invoiceFiles']);
        Route::post('claim-requests/{id}/request-files', [ClaimRequestController::class, 'requestFiles']);

        Route::get('claim-requests/service/{id}', [ClaimRequestController::class, 'getServiceMember']);

        // Report API
        Route::prefix('report')->group(function () {
            Route::prefix('/logs')->group(function () {
                Route::get('/', [ReportLogController::class, 'index']);
                Route::get('/export', [ReportLogController::class, 'generateDataRequestLogExcel']);
            });
        });

    });

    Route::get('province', [ProvinceController::class, 'index']);
    Route::get('service', [ServiceController::class, 'index']);
    Route::get('city', [CityController::class, 'index']);
    Route::get('district', [DistrictController::class, 'index']);
    Route::get('village', [VillageController::class, 'index']);
    Route::get('options', [OptionController::class, 'index']);

    Route::get('final-log/{id}', [ClaimController::class, 'downloadFinalLog'])->name('claim.download-final-log');
});
