<?php

use App\Http\Controllers\Bookings\ApprovePaymentVerificationController;
use App\Http\Controllers\Bookings\ApprovePurchaseOrderController;
use App\Http\Controllers\Bookings\CancelBookingController;
use App\Http\Controllers\Bookings\CreateBankingInvoiceTransactionController;
use App\Http\Controllers\Bookings\CreateBookingController;
use App\Http\Controllers\Bookings\CreateBookingLockController;
use App\Http\Controllers\Bookings\CreateBookingPaymentController;
use App\Http\Controllers\Bookings\CreateBookingRefundController;
use App\Http\Controllers\Bookings\CreateBookingRefundCreditNoteController;
use App\Http\Controllers\Bookings\CreatePaymentVerificationController;
use App\Http\Controllers\Bookings\CreateProformaInvoiceTransaction;
use App\Http\Controllers\Bookings\DeleteBookingController;
use App\Http\Controllers\Bookings\DeleteBookingLockController;
use App\Http\Controllers\Bookings\DeletePurchaseOrderPdfController;
use App\Http\Controllers\Bookings\ExpireBookingPaymentController;
use App\Http\Controllers\Bookings\FetchBookingController;
use App\Http\Controllers\Bookings\FetchBookingPaymentQuotationController;
use App\Http\Controllers\Bookings\ListBookingsController;
use App\Http\Controllers\Bookings\ListBookingsJobController;
use App\Http\Controllers\Bookings\MergeBookingController;
use App\Http\Controllers\Bookings\RegenerateBookingEInvoiceController;
use App\Http\Controllers\Bookings\RegenerateBookingPaymentRVController;
use App\Http\Controllers\Bookings\RegenerateInvoiceBookingController;
use App\Http\Controllers\Bookings\RestoreBookingController;
use App\Http\Controllers\Bookings\UpdateBookingAmountController;
use App\Http\Controllers\Bookings\UpdateBookingController;
use App\Http\Controllers\Bookings\UpdateBookingOrderReferenceController;
use App\Http\Controllers\Bookings\UpdateBookingOwnerController;
use App\Http\Controllers\Bookings\UpdateBookingRecipientController;
use App\Http\Controllers\Bookings\UploadPurchaseOrderController;
use Illuminate\Support\Facades\Route;

Route::group(['prefix' => 'booking', 'as' => 'booking.'], function () {
    Route::get('/show/{marking}', [FetchBookingController::class, 'fetch'])->name('show');
    Route::get('/list', [ListBookingsController::class, 'list'])->name('list');
    Route::get('/list/job', [ListBookingsJobController::class, 'list'])->name('list.job');
    Route::post('/create', [CreateBookingController::class, 'create'])->name('create');
    Route::post('/create/lock', [CreateBookingLockController::class, 'create'])->name('create.lock');
    Route::delete('/delete/lock/{id}', [DeleteBookingLockController::class, 'delete'])->name('delete.lock');
    Route::put('/update/{id}', [UpdateBookingController::class, 'update'])->name('update');
    Route::put('/recipient/update/{id}', [UpdateBookingRecipientController::class, 'update'])->name('update.recipient');
    Route::put('/cancel/{id}', [CancelBookingController::class, 'cancel'])->name('cancel');
    Route::put('/restore/{id}', [RestoreBookingController::class, 'restore'])->name('restore');
    Route::delete('/delete/{id}', [DeleteBookingController::class, 'delete'])->name('delete');
    Route::post('/regenerate/invoice/{id}', [RegenerateInvoiceBookingController::class, 'regenerate'])->name('regenerate.invoice');

    Route::put('/owner/update/{id}', [UpdateBookingOwnerController::class, 'update'])->name('owner.update');

    Route::group(['prefix' => '{id}/payment', 'as' => 'payment.'], function () {
        Route::post('quotation', [FetchBookingPaymentQuotationController::class, 'fetch'])->name('quotation');
        Route::post('create', [CreateBookingPaymentController::class, 'create'])->name('create');
        Route::post('{payment_id}/verification/create', [CreatePaymentVerificationController::class, 'create'])->name('verification.create');
        Route::put('/{payment_id}/approval/{status}', [ApprovePaymentVerificationController::class, 'approve'])->where('status', 'approve|reject')->name('approval');
        Route::post('delete', [ExpireBookingPaymentController::class, 'expire'])->name('expire');
    });

    Route::group(['prefix' => '{id}/refund', 'as' => 'refund.'], function () {
        Route::post('{payment_id}/create', [CreateBookingRefundController::class, 'create'])->name('create');
        Route::post('{payment_id}/credit_note/create', [CreateBookingRefundCreditNoteController::class, 'create'])->name('credit_note.create');
    });

    Route::post('{id}/purchase_order/verification', [ApprovePurchaseOrderController::class, 'approve'])->name('po.approval');
    Route::post('{id}/purchase_order/pdf', [UploadPurchaseOrderController::class, 'upload'])->name('po.pdf');
    Route::delete('{id}/purchase_order/pdf', [DeletePurchaseOrderPdfController::class, 'delete'])->name('po.pdf.delete');

    Route::put('{id}/updateAmount', [UpdateBookingAmountController::class, 'update'])->name('booking_amount.update');
    Route::put('{id}/updateAmountWithPO', [UpdateBookingAmountController::class, 'updateOnHold'])->name('amount.update');
    Route::put('{id}/updateOrderReferences', [UpdateBookingOrderReferenceController::class, 'update'])->name('booking_order_reference.update');

    Route::post('/merge', [MergeBookingController::class, 'merge'])->name('merge');

    Route::post('{id}/proforma/create', [CreateProformaInvoiceTransaction::class, 'create'])->name('proforma.create');
    Route::post('{id}/banking/create', [CreateBankingInvoiceTransactionController::class, 'create'])->name('banking.create');


    Route::group(['prefix' => '{id}/receipt', 'as' => 'receipt.'], function () {
        Route::post('/', [RegenerateBookingPaymentRVController::class, 'regenerate'])->name('regenerate');
    });
    Route::group(['prefix' => '{id}/einvoice', 'as' => 'einvoice.'], function () {
        Route::post('/', [RegenerateBookingEInvoiceController::class, 'regenerate'])->name('regenerate');
        Route::post('/try', [RegenerateBookingEInvoiceController::class, 'tryRegenerate'])->name('try.regenerate');
    });
    Route::group(['prefix' => 'batch/einvoice', 'as' => 'batch.'], function () {
        Route::get('/process', [RegenerateBookingEInvoiceController::class, 'batchProcess'])->name('process');
    });
});
