<?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\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\DiagnosisExclusionController;
use Modules\Internal\Http\Controllers\Api\DistrictController;
use Modules\Internal\Http\Controllers\Api\DivisionController;
use Modules\Internal\Http\Controllers\Api\DoctorController;
use Modules\Internal\Http\Controllers\Api\DrugController;
use Modules\Internal\Http\Controllers\Api\FormulariumController;
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\SpecialityController;
use Modules\Internal\Http\Controllers\Api\VillageController;
use Modules\Internal\Http\Controllers\ClaimEncounterController;

/*
|--------------------------------------------------------------------------
| 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('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::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::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}/members', [CorporateMemberController::class, 'index']);
        Route::post('corporates/{corporate_id}/members/import', [CorporateMemberController::class, 'import']);
        Route::put('members/{member_id}/activation', [CorporateMemberController::class, 'activation']);


        Route::get('corporates/{corporate_id}/diagnosis-exclusions', [DiagnosisExclusionController::class, 'index']);
        Route::post('corporates/{corporate_id}/diagnosis-exclusions/store', [DiagnosisExclusionController::class, 'storeExclusion']);
        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/exclusion', [CorporateServiceController::class, 'storeExclusion']);

        Route::get('corporates/{corporate_id}/formulariums', [CorporateFormulariumController::class, 'index']);
        Route::put('corporates/{corporate_id}/formulariums/{formularium_id}/{action}', [CorporateFormulariumController::class, 'updateStatus']);

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

        Route::get('master/diagnosis', [DiagnosisController::class, 'index']);
        Route::get('master/diagnosis/search', [DiagnosisController::class, 'search']);
        Route::get('master/drugs', [DrugController::class, 'index']);
        Route::get('master/formulariums', [FormulariumController::class, 'index']);
        Route::post('master/formulariums', [FormulariumController::class, 'store']);
        Route::post('master/formulariums/import', [FormulariumController::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', [ClaimController::class, 'store']);
        Route::get('claims/{id}', [ClaimController::class, 'show']);
        Route::post('check-limit', [ClaimController::class, 'checkLimit']);

        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::resource('live-chat', LivechatController::class);

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

        Route::post('generate-log/{member_id}', [CorporateMemberController::class, 'generateLog']);
        
        Route::get('claim-requests', [ClaimRequestController::class, 'index'])->name('claim-requests.index');
        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::get('province', [ProvinceController::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');
});
