<?php

use App\Http\Controllers\DashboardController;
use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use App\Http\Controllers\ItemCategoryController;
use App\Http\Controllers\ItemController;
use App\Http\Controllers\ItemVariationController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\PurchaseRequestController;
use App\Http\Controllers\PurchaseOrderController;
use App\Http\Controllers\GrnController;
use App\Http\Controllers\GatepassController;
use App\Http\Controllers\ChartOfAccountController;
use App\Http\Controllers\AccountController;
use App\Http\Controllers\AccountingReportController;
use App\Http\Controllers\AccountTransactionController;
use App\Http\Controllers\ManualTransactionController;
use App\Http\Controllers\LoggingController;
use App\Http\Controllers\UomController;
use App\Http\Controllers\MachineController;
use App\Http\Controllers\BomController;
use App\Http\Controllers\WmsDemoController;
use App\Http\Controllers\WmsController;
use App\Http\Controllers\ManufacturingController;
use App\Http\Controllers\WarehouseBinController;
use App\Http\Controllers\StockTransferController;
use App\Http\Controllers\ItemSupplierController;
use App\Http\Controllers\LocationController;
use App\Http\Controllers\WarehouseController;
use App\Http\Controllers\VariationsController;
use App\Http\Controllers\QcController;
use App\Http\Controllers\ShopController;
use App\Http\Controllers\ManufacturingBOMController;
use App\Http\Controllers\Api\Desktop\LicenseAPIController;
use App\Http\Controllers\Api\Desktop\SyncAPIController;
use App\Http\Controllers\Api\Desktop\DesktopController;
use App\Http\Controllers\Api\Desktop\APIAuthController;
use App\Http\Controllers\Api\Desktop\PushController;
use App\Http\Controllers\Api\Desktop\PullController;
use App\Http\Controllers\Api\Desktop\AttachmentSyncController;


Route::get('/', function () {
	return view('auth.login');
});

// Public PR search route for Select2 (search by pr_number)
Route::get('purchase-requests/search', [PurchaseRequestController::class, 'search'])->name('purchase-requests.search');

// PO search route for Select2 (search by po_number)
Route::get('purchase-orders/search', [PurchaseOrderController::class, 'searchPurchaseOrders'])->name('purchase-orders.search');

// QC API routes
Route::prefix('api')->name('api.')->group(function () {
    Route::post('qc', [App\Http\Controllers\Api\QcController::class, 'store'])->name('qc.store');
    Route::get('qc/{qc}', [App\Http\Controllers\Api\QcController::class, 'show'])->name('qc.show');
    Route::get('igp/search', [App\Http\Controllers\Api\QcController::class, 'searchIgps'])->name('igp.search');
    Route::get('warehouse/{warehouse}/bins', [App\Http\Controllers\Api\QcController::class, 'getWarehouseBins'])->name('warehouse.bins');
    Route::get('igp/{igp}/items', [App\Http\Controllers\Api\QcController::class, 'getIgpItems'])->name('igp.items');
});


// Route::middleware('auth')->group(function () {
//     Route::get('/profile', [ProfileController::class, 'show'])->name('profile.show');
//     Route::get('/profile/edit', [ProfileController::class, 'edit'])->name('profile.edit');
//     Route::patch('/profile/update', [ProfileController::class, 'update'])->name('profile.update');
// });

Route::middleware(['auth','verified','request.logging','check.active.user'])->group(function () {
	// Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
	// Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
	// Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');

	Route::get('/dashboard',[DashboardController::class, 'index'])->name('dashboard');
	Route::get('/profile', [ProfileController::class, 'show'])->name('profile.show');
    Route::get('/profile/edit', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile/update', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');




	// Item Categories
    Route::get('item-categories/search', [ItemCategoryController::class, 'search'])->name('item-categories.search');
    Route::get('api/categories', [ItemCategoryController::class, 'search'])->name('api.categories');
	Route::patch('item-categories/{item_category}/toggle-status', [ItemCategoryController::class, 'toggleStatus'])->name('item-categories.toggle-status');
	Route::resource('item-categories', ItemCategoryController::class);

	// Items + Variations
	Route::get('items/search', [ItemController::class, 'search'])->name('items.search');
	Route::post('items/check-sku', [ItemController::class, 'checkSku'])->name('items.check-sku');
	Route::get('items/generate-sku', [ItemController::class, 'generateSku'])->name('items.generate-sku');
	Route::get('items/chart-account-children', [ItemController::class, 'getChartAccountChildren'])->name('items.chart-account-children');
	Route::get('items/variations/search', [ItemVariationController::class, 'search'])->name('items.variations.search');
	Route::patch('items/{item}/variations/{variation}/toggle-active', [ItemVariationController::class, 'toggleActive'])->name('items.variations.toggle-active');
	Route::patch('items/{item}/toggle-status', [ItemController::class, 'toggleStatus'])->name('items.toggle-status');
	Route::resource('items', ItemController::class)->except(['show']);
	Route::resource('items.variations', ItemVariationController::class);

	// Global Variations Management
	Route::get('variations/data', [VariationsController::class, 'getData'])->name('variations.data');
	Route::patch('variations/{variation}/toggle-active', [VariationsController::class, 'toggleActive'])->name('variations.toggle-active');
	Route::resource('variations', VariationsController::class);

	// Item Supplier Management
	Route::post('items/{item}/suppliers', [ItemController::class, 'addSupplier'])->name('items.suppliers.add');
	Route::delete('item-suppliers/{}', [ItemController::class, 'removeSupplier'])->name('items.suppliers.remove');
	Route::patch('item-suppliers/{}', [ItemController::class, 'updateSupplier'])->name('items.suppliers.update');
	Route::get('items/{item}/supplier-info', [ItemController::class, 'getSupplierInfo'])->name('items.supplier-info');

	// UOMs
	Route::get('uoms/search', [UomController::class, 'search'])->name('uoms.search');
	Route::resource('uoms', UomController::class);

	// Machines
	Route::get('machines/search', [MachineController::class, 'search'])->name('machines.search');
	Route::resource('machines', MachineController::class);

	// BOMs
	Route::post('boms/{bom}/components', [BomController::class, 'addComponent'])->name('boms.components.add');
	Route::delete('boms/{bom}/components/{component}', [BomController::class, 'removeComponent'])->name('boms.components.remove');
	Route::resource('boms', BomController::class);

	// Contacts
	Route::get('contacts/search', [ContactController::class, 'search'])->name('contacts.search');
	Route::post('contacts/check-username', [ContactController::class, 'checkUsername'])->name('contacts.check-username');
	Route::patch('contacts/{contact}/toggle-active', [ContactController::class, 'toggleActive'])->name('contacts.toggle-active');
	Route::patch('contacts/{contact}/toggle-status', [ContactController::class, 'toggleStatus'])->name('contacts.toggle-status');
	Route::resource('contacts', ContactController::class);

	// Customer Routes
	Route::resource('customers', App\Http\Controllers\CustomerController::class);

// Supplier Routes
Route::resource('suppliers', App\Http\Controllers\SupplierController::class);
Route::get('suppliers/generate-code', [App\Http\Controllers\SupplierController::class, 'generateCode'])->name('suppliers.generate-code');


	// Contacts API Routes
	Route::prefix('api')->name('api.')->group(function () {
		Route::get('contacts/types', [App\Http\Controllers\Api\ContactController::class, 'types'])->name('contacts.types');
		Route::get('contacts/by-type/{type}', [App\Http\Controllers\Api\ContactController::class, 'byType'])->name('contacts.by-type');
		Route::get('contacts/search', [App\Http\Controllers\Api\ContactController::class, 'search'])->name('contacts.search');
		Route::get('contacts/search/pr', [App\Http\Controllers\Api\ContactController::class, 'searchPR'])->name('contacts.searchPR');
		Route::apiResource('contacts', App\Http\Controllers\Api\ContactController::class);
	});

	// Purchase Requests
	Route::get('purchase-requests/users/search', [PurchaseRequestController::class, 'searchUsers'])->name('purchase-requests.users.search');
	Route::get('purchase-requests/search', [PurchaseRequestController::class, 'search'])->name('purchase-requests.search1');
	Route::get('api/internal/pr-items', [PurchaseRequestController::class, 'prItems'])->name('api.pr-items');
	Route::get('purchase-requests/approval', [PurchaseRequestController::class, 'approvalIndex'])->name('purchase-requests.approval');
	Route::post('purchase-requests/{purchaseRequest}/submit', [PurchaseRequestController::class, 'submit'])->name('purchase-requests.submit');
	Route::post('purchase-requests/{purchaseRequest}/approve', [PurchaseRequestController::class, 'approve'])->name('purchase-requests.approve');
	Route::post('purchase-requests/{purchaseRequest}/reject', [PurchaseRequestController::class, 'reject'])->name('purchase-requests.reject');
	Route::post('purchase-requests/{purchaseRequest}/cancel', [PurchaseRequestController::class, 'cancel'])->name('purchase-requests.cancel');
	Route::post('purchase-requests/{purchaseRequest}/convert-to-po', [PurchaseRequestController::class, 'convertToPo'])->name('purchase-requests.convert-to-po');
	Route::patch('purchase-requests/{purchaseRequest}/update-status', [PurchaseRequestController::class, 'updateStatus'])->name('purchase-requests.update-status');
	Route::resource('purchase-requests', PurchaseRequestController::class);

	// Purchase Orders
	Route::get('purchase-orders/create-from-pr/{purchaseRequest}', [PurchaseOrderController::class, 'createFromPR'])->name('purchase-orders.create-from-pr');
	Route::get('purchase-orders/{purchaseOrder}/items', [PurchaseOrderController::class, 'getItems'])->name('purchase-orders.items');
    Route::patch('purchase-orders/{purchaseOrder}/update-status', [PurchaseOrderController::class, 'updateStatus'])->name('purchase-orders.update-status');
    Route::post('purchase-orders/{purchaseOrder}/cancel', [PurchaseOrderController::class, 'cancel'])->name('purchase-orders.cancel');
	Route::resource('purchase-orders', PurchaseOrderController::class)->except('show');
    Route::get('purchase-order/{purchaseOrder}/show', [PurchaseOrderController::class, 'show'])->name('purchase-orders.show');




	// GRNs
	Route::patch('grns/{grn}/update-status', [GrnController::class, 'updateStatus'])->name('grns.update-status');
	Route::get('grns/create-from-igp/{gatePass}', [GrnController::class, 'createFromIGP'])->name('grns.create-from-igp');
    Route::post('grns/store-from-igp', [GrnController::class, 'storeFromIGP'])->name('grns.store-from-igp');
    	Route::get('grns/po-details', [GrnController::class, 'getPODetails'])->name('grns.po-details');
	Route::get('grns/available-igps', [GrnController::class, 'getAvailableIGPs'])->name('grns.available-igps');
	Route::get('grns/search-igps', [GrnController::class, 'searchIGPs'])->name('grns.search-igps');
	Route::get('grns/search-pos', [GrnController::class, 'searchPurchaseOrders'])->name('grns.search-pos');
	Route::get('grns/available-for-qc', [GrnController::class, 'getAvailableForQc'])->name('grns.available-for-qc');
	Route::post('grns/{grn}/create-qc', [GrnController::class, 'createQc'])->name('grns.create-qc');
    Route::resource('grns', GrnController::class)->except(['store']);
    Route::post('grns', [GrnController::class, 'store'])->name('grns.store');


// Temporary debug route
Route::post('/test-grn-form', function(Request $request) {
    dd('Form reached test endpoint', $request->all());
})->name('test.grn.form');

	// QC (Quality Control)
	Route::get('qcs/filter/search', [QcController::class, 'filterSearch'])->name('qcs.filter.search');
	Route::get('qcs/filter/igpsearch', [QcController::class, 'filterIgpSearch'])->name('qcs.filter.igpsearch');

	Route::get('qcs/filter/po-search', [QcController::class, 'filterPoSearch'])->name('qcs.filter.po-search');
	Route::get('qcs/create', [QcController::class, 'create'])->name('qcs.create');
	Route::get('qcs/create/{grn}', [QcController::class, 'create'])->name('qcs.create-for-grn');
	Route::post('qcs', [QcController::class, 'store'])->name('qcs.store');
	Route::get('qcs/{qc}/items', [QcController::class, 'getQcItems'])->name('qcs.items');
	Route::get('qcs/igp/{gatepass}/items', [QcController::class, 'getIgpItems'])->name('qcs.igp.items');
	Route::post('qcs/{qc}/cancel', [QcController::class, 'cancel'])->name('qcs.cancel');
	Route::post('qcs/{qc}/add-to-stock', [QcController::class, 'addToStock'])->name('qcs.add-to-stock');
	Route::get('qcs/warehouse-stock', [QcController::class, 'getWarehouseStock'])->name('qcs.warehouse-stock');
    Route::get('qcs/warehouse-bins', [QcController::class, 'getWarehouseBins'])->name('qcs.warehouse-bins');
	Route::get('inspectors/search', [QcController::class, 'inspectorSearch'])->name('inspector.search');

    Route::resource('qcs', QcController::class)->except(['create', 'store']);

	// QC API Routes
	Route::prefix('api')->name('api.')->group(function () {
		Route::get('qc/search', [App\Http\Controllers\Api\QcController::class, 'search'])->name('qc.search');
		Route::get('qc/{qc}', [App\Http\Controllers\Api\QcController::class, 'show'])->name('qc.show');
		Route::get('igp/search', [App\Http\Controllers\Api\QcController::class, 'searchIgps'])->name('igp.search');
		Route::get('warehouse/{warehouse}/bins', [App\Http\Controllers\Api\QcController::class, 'getWarehouseBins'])->name('warehouse.bins');
		Route::get('igp/{igp}/items', [App\Http\Controllers\Api\QcController::class, 'getIgpItems'])->name('igp.items');
		Route::get('warehouses', [WarehouseController::class, 'getWarehousesForApi'])->name('warehouses.index');

		// GRN API Routes
		Route::post('grn', [App\Http\Controllers\Api\GrnController::class, 'store'])->name('grn.store');
		Route::get('grn/{grn}', [App\Http\Controllers\Api\GrnController::class, 'show'])->name('grn.show');
	});

	// Gate Pass Routes (consolidated)
	// Route::patch('gate-passes/{gatePass}/update-status', [GatePassController::class, 'updateStatus'])->name('gate-passes.update-status');
	// Route::get('gate-passes/{gatePass}/print', [GatePassController::class, 'print'])->name('gate-passes.print');
	// Route::get('gate-passes/search', [GatePassController::class, 'search'])->name('gate-passes.search');
	// Route::resource('gate-passes', GatePassController::class);

	// Inspection Requests
	Route::post('inspection-requests', [\App\Http\Controllers\InspectionRequestController::class, 'store'])->name('inspection-requests.store');
	Route::post('inspection-requests/{inspectionRequest}/cancel', [\App\Http\Controllers\InspectionRequestController::class, 'cancel'])->name('inspection-requests.cancel');



	// Gatepasses
	Route::patch('gatepasses/{gatepass}/update-status', [GatePassController::class, 'updateStatus'])->name('gatepasses.update-status');
	Route::post('gatepasses/{gatepass}/cancel', [GatePassController::class, 'cancel'])->name('gatepasses.cancel');
	Route::get('igps/available-for-qc', [GatePassController::class, 'getAvailableForQc'])->name('igps.available-for-qc');
	Route::resource('gatepasses', GatePassController::class);

// Outward Gate Passes Routes
Route::prefix('outward-gate-passes')->name('outward-gate-passes.')->group(function() {
    Route::post('/{outwardGatePass}/complete', [App\Http\Controllers\OutwardGatePassController::class, 'complete'])->name('complete');
    Route::get('/', [App\Http\Controllers\OutwardGatePassController::class, 'index'])->name('index');
    Route::get('/create', [App\Http\Controllers\OutwardGatePassController::class, 'create'])->name('create');
    Route::post('/', [App\Http\Controllers\OutwardGatePassController::class, 'store'])->name('store');
    Route::get('/{outwardGatePass}', [App\Http\Controllers\OutwardGatePassController::class, 'show'])->name('show');
    Route::get('/{outwardGatePass}/edit', [App\Http\Controllers\OutwardGatePassController::class, 'edit'])->name('edit');
    Route::patch('/{outwardGatePass}', [App\Http\Controllers\OutwardGatePassController::class, 'update'])->name('update');
    Route::get('/{outwardGatePass}/issue', [App\Http\Controllers\OutwardGatePassController::class, 'issue'])->name('issue');
    Route::get('/{outwardGatePass}/print', [App\Http\Controllers\OutwardGatePassController::class, 'print'])->name('print');
    Route::get('/invoice/{factoryInvoice}/items', [App\Http\Controllers\OutwardGatePassController::class, 'getInvoiceItems'])->name('invoice.items');
});

	// Accounting System
	Route::get('accounts/dashboard', [AccountController::class, 'dashboard'])->name('accounts.dashboard');
	Route::resource('chart-of-accounts', ChartOfAccountController::class);
	Route::resource('accounts', AccountController::class);
	Route::resource('account-transactions', AccountTransactionController::class);
	Route::get('accounts/{account}/transactions', [AccountTransactionController::class, 'forAccount'])->name('accounts.transactions');

    // Manual Transaction Module
    Route::get('manual-transactions/create', [ManualTransactionController::class, 'create'])->name('manual-transactions.create');
    Route::post('manual-transactions', [ManualTransactionController::class, 'store'])->name('manual-transactions.store');
    Route::get('manual-transactions/pending-documents', [ManualTransactionController::class, 'getPendingDocuments'])->name('manual-transactions.pending-documents');

    // Accounting Reports
    Route::prefix('accounting/reports')->name('accounting.reports.')->group(function () {
        Route::get('general-ledger', [AccountingReportController::class, 'generalLedger'])->name('general-ledger');
        Route::get('trial-balance', [AccountingReportController::class, 'trialBalance'])->name('trial-balance');
        Route::get('profit-loss', [AccountingReportController::class, 'profitLoss'])->name('profit-loss');
        Route::get('balance-sheet', [AccountingReportController::class, 'balanceSheet'])->name('balance-sheet');
        Route::get('day-book', [AccountingReportController::class, 'dayBook'])->name('day-book');
    });

	// Logging System
	Route::get('logging', [LoggingController::class, 'index'])->name('logging.index');
	Route::get('logging/activity', [LoggingController::class, 'getActivityLogs'])->name('logging.activity');
	Route::get('logging/laravel', [LoggingController::class, 'getLaravelLogs'])->name('logging.laravel');
	Route::get('logging/error', [LoggingController::class, 'getErrorLogs'])->name('logging.error');
	Route::get('logging/properties/{id}', [LoggingController::class, 'getActivityProperties'])->name('logging.properties');
	Route::post('logging/clear', [LoggingController::class, 'clearLogs'])->name('logging.clear');

	// WMS Demo
	Route::get('wms-demo', [WmsDemoController::class, 'index'])->name('wms.demo');
	Route::post('wms-demo/workflow', [WmsDemoController::class, 'demoWorkflow'])->name('wms.demo.workflow');
	Route::get('wms-demo/stock-balances', [WmsDemoController::class, 'getStockBalances'])->name('wms.demo.stock-balances');
	Route::get('wms-demo/ledger-entries', [WmsDemoController::class, 'getLedgerEntries'])->name('wms.demo.ledger-entries');

	// WMS (Warehouse Management System)
	Route::get('wms', [WmsController::class, 'index'])->name('wms.index');
	Route::get('wms/stock-balances', [WmsController::class, 'stockBalances'])->name('wms.stock-balances');
	Route::post('wms/process-igp/{grn}', [WmsController::class, 'processIGP'])->name('wms.process-igp');
	Route::get('wms/ledger-data', [WmsController::class, 'getLedgerData'])->name('wms.ledger-data');
	Route::get('wms/stock-data', [WmsController::class, 'getStockData'])->name('wms.stock-data');

	// Manufacturing
	Route::get('manufacturing', [ManufacturingController::class, 'index'])->name('manufacturing.index');
	Route::get('manufacturing/work-orders', [ManufacturingController::class, 'workOrders'])->name('manufacturing.work-orders');
	Route::get('manufacturing/work-orders/{id}', [ManufacturingController::class, 'showWorkOrder'])->name('manufacturing.work-orders.show');
	Route::get('manufacturing/work-orders/{id}/issue', [ManufacturingController::class, 'issueMaterials'])->name('manufacturing.work-orders.issue');
	Route::post('manufacturing/work-orders/{id}/issue', [ManufacturingController::class, 'processMaterialIssue'])->name('manufacturing.work-orders.issue.process');
	Route::get('manufacturing/work-orders/{id}/receive', [ManufacturingController::class, 'receiveFinishedGoods'])->name('manufacturing.work-orders.receive');
	Route::post('manufacturing/work-orders/{id}/receive', [ManufacturingController::class, 'processFGReceive'])->name('manufacturing.work-orders.receive.process');
	Route::post('manufacturing/work-orders/{id}/quality-check', [ManufacturingController::class, 'createQualityCheck'])->name('manufacturing.work-orders.quality-check');
	Route::get('manufacturing/demo', [ManufacturingController::class, 'demo'])->name('manufacturing.demo');
	Route::post('manufacturing/demo', [ManufacturingController::class, 'runDemo'])->name('manufacturing.demo.run');
	Route::get('manufacturing/stock-data', [ManufacturingController::class, 'getStockData'])->name('manufacturing.stock-data');
	Route::get('manufacturing/ledger-data', [ManufacturingController::class, 'getLedgerData'])->name('manufacturing.ledger-data');

	// Manufacturing BOM Routes
	Route::get('manufacturing/boms/search-finished-goods', [ManufacturingBOMController::class, 'searchFinishedGoods'])->name('manufacturing.boms.search-finished-goods');
	Route::get('manufacturing/boms/search-raw-materials', [ManufacturingBOMController::class, 'searchRawMaterials'])->name('manufacturing.boms.search-raw-materials');
	Route::post('manufacturing/boms/{manufacturingBom}/steps', [ManufacturingBOMController::class, 'addStep'])->name('manufacturing.boms.add-step');
	Route::delete('manufacturing/boms/{manufacturingBom}/steps/{step}', [ManufacturingBOMController::class, 'removeStep'])->name('manufacturing.boms.remove-step');
	Route::post('manufacturing/boms/{manufacturingBom}/ingredients', [ManufacturingBOMController::class, 'addIngredient'])->name('manufacturing.boms.add-ingredient');
	Route::delete('manufacturing/boms/{manufacturingBom}/ingredients/{ingredient}', [ManufacturingBOMController::class, 'removeIngredient'])->name('manufacturing.boms.remove-ingredient');
	Route::resource('manufacturing/boms', ManufacturingBOMController::class)->names([
		'index' => 'manufacturing.boms.index',
		'create' => 'manufacturing.boms.create',
		'store' => 'manufacturing.boms.store',
		'show' => 'manufacturing.boms.show',
		'edit' => 'manufacturing.boms.edit',
		'update' => 'manufacturing.boms.update',
		'destroy' => 'manufacturing.boms.destroy'
	])->parameters([
		'boms' => 'manufacturingBom'
	]);
	Route::get('manufacturing/boms/{id}/download-report', [ManufacturingBOMController::class, 'downloadReport'])->name('manufacturing.boms.download-report');
	Route::get('manufacturing/boms/{id}/download-report/{pageSize}', [ManufacturingBOMController::class, 'downloadReport'])->name('manufacturing.boms.download-report-size');
	Route::get('manufacturing/boms/{manufacturingBom}/details', [ManufacturingBOMController::class, 'getBOMDetails'])->name('manufacturing.boms.details');
	Route::get('manufacturing/boms/{manufacturingBom}/cost-data', [ManufacturingBOMController::class, 'getBOMCostData'])->name('manufacturing.boms.cost-data');
	Route::post('manufacturing/boms/check-exists', [ManufacturingBOMController::class, 'checkBOMExists'])->name('manufacturing.boms.check-exists');
	Route::get('manufacturing/boms/debug-finished-goods', [ManufacturingBOMController::class, 'debugFinishedGoods'])->name('manufacturing.boms.debug-finished-goods');

	// Warehouse Pieces Management
	Route::get('warehouse-pieces', [App\Http\Controllers\WarehousePieceController::class, 'index'])->name('warehouse-pieces.index');
	Route::get('warehouse-pieces/{warehousePiece}', [App\Http\Controllers\WarehousePieceController::class, 'show'])->name('warehouse-pieces.show');
	Route::post('warehouse-pieces/{warehousePiece}/update-status', [App\Http\Controllers\WarehousePieceController::class, 'updateStatus'])->name('warehouse-pieces.update-status');
	Route::get('warehouse-pieces/statistics', [App\Http\Controllers\WarehousePieceController::class, 'getStatistics'])->name('warehouse-pieces.statistics');
	Route::get('warehouse-pieces/warehouse/{warehouseId}', [App\Http\Controllers\WarehousePieceController::class, 'getByWarehouse'])->name('warehouse-pieces.by-warehouse');
	Route::get('warehouse-pieces/item/{itemId}', [App\Http\Controllers\WarehousePieceController::class, 'getByItem'])->name('warehouse-pieces.by-item');

	// Reports
	Route::get('reports/piece-production', [App\Http\Controllers\ReportController::class, 'pieceProductionReport'])->name('reports.piece-production');
	Route::get('reports/piece-inventory', [App\Http\Controllers\ReportController::class, 'pieceInventoryReport'])->name('reports.piece-inventory');
	Route::get('reports/production-summary', [App\Http\Controllers\ReportController::class, 'productionSummaryReport'])->name('reports.production-summary');
	Route::get('reports/piece-statistics', [App\Http\Controllers\ReportController::class, 'getPieceStatistics'])->name('reports.piece-statistics');
	Route::get('reports/warehouse-piece-statistics', [App\Http\Controllers\ReportController::class, 'getWarehousePieceStatistics'])->name('reports.warehouse-piece-statistics');

	// Production Report (date wise)
	Route::get('reports/production', [App\Http\Controllers\ReportController::class, 'productionReport'])->name('reports.production');
	Route::get('reports/production-stats', [App\Http\Controllers\ReportController::class, 'getProductionStats'])->name('reports.production-stats');

	// Stock Position Report (date wise)
	Route::get('reports/stock-position', [App\Http\Controllers\ReportController::class, 'stockPositionReport'])->name('reports.stock-position');

	// Distribution Report (Shop Invoices)
	Route::get('reports/distribution', [App\Http\Controllers\ReportController::class, 'distributionReport'])->name('reports.distribution');
	Route::get('reports/distribution-stats', [App\Http\Controllers\ReportController::class, 'getDistributionStats'])->name('reports.distribution-stats');

	// Vendor Cash Flow Report
	Route::get('reports/vendor-cash-flow', [App\Http\Controllers\ReportController::class, 'vendorCashFlowReport'])->name('reports.vendor-cash-flow');
	Route::get('reports/vendor-cash-flow-stats', [App\Http\Controllers\ReportController::class, 'getVendorCashFlowStats'])->name('reports.vendor-cash-flow-stats');

	// Warehouse Bins
	Route::get('warehouse-bins/data', [WarehouseBinController::class, 'getData'])->name('warehouse-bins.data');
	Route::patch('warehouse-bins/{warehouse_bin}/toggle-active', [WarehouseBinController::class, 'toggleActive'])->name('warehouse-bins.toggle-active');
	Route::resource('warehouse-bins', WarehouseBinController::class);

	// Stock Transfers
	Route::get('stock-transfers/data', [StockTransferController::class, 'getData'])->name('stock-transfers.data');
	Route::resource('stock-transfers', StockTransferController::class);

	// Stock Management
	Route::get('stocks/get-data', [App\Http\Controllers\StockController::class, 'getData'])->name('stocks.get-data');
	Route::get('stocks/export', [App\Http\Controllers\StockController::class, 'export'])->name('stocks.export');
	Route::resource('stocks', App\Http\Controllers\StockController::class);
// Route::get('/stocks/data', [App\Http\Controllers\StockController::class, 'getData'])->name('stocks.get-data');
	// Stock Ledger
	Route::get('stock-ledgers/get-data', [App\Http\Controllers\StockLedgerController::class, 'getData'])->name('stock-ledgers.get-data');
	Route::get('stock-ledgers/export', [App\Http\Controllers\StockLedgerController::class, 'export'])->name('stock-ledgers.export');
	Route::resource('stock-ledgers', App\Http\Controllers\StockLedgerController::class);

	// Item Suppliers
	Route::get('item-suppliers/data', [ItemSupplierController::class, 'getData'])->name('item-suppliers.data');
	Route::resource('item-suppliers', ItemSupplierController::class);

	// Locations
	Route::get('locations/search', [LocationController::class, 'search'])->name('locations.search');
	Route::get('locations/data', [LocationController::class, 'getData'])->name('locations.data');
	Route::resource('locations', LocationController::class);

	// Warehouses
	Route::get('warehouses/search', [WarehouseController::class, 'search'])->name('warehouses.search');
	Route::get('warehouses/data', [WarehouseController::class, 'getData'])->name('warehouses.data');
	Route::get('warehouses/current-stock', [WarehouseController::class, 'currentStock'])->name('warehouses.current-stock');
	Route::get('warehouses/current-stock/data', [WarehouseController::class, 'getCurrentStockData'])->name('warehouses.current-stock.data');
	Route::get('warehouses/current-stock-finished-goods', [WarehouseController::class, 'currentStockFinishedGoods'])->name('warehouses.current-stock-finished-goods');
	Route::get('warehouses/current-stock-finished-goods/data', [WarehouseController::class, 'getCurrentStockFinishedGoodsData'])->name('warehouses.current-stock-finished-goods.data');
	Route::get('warehouses/current-stock-raw-materials', [WarehouseController::class, 'currentStockRawMaterials'])->name('warehouses.current-stock-raw-materials');
	Route::get('warehouses/current-stock-raw-materials/data', [WarehouseController::class, 'getCurrentStockRawMaterialsData'])->name('warehouses.current-stock-raw-materials.data');
	Route::get('warehouses/stock-history', [WarehouseController::class, 'stockHistory'])->name('warehouses.stock-history');
	Route::get('warehouses/stock-history/data', [WarehouseController::class, 'getStockHistoryData'])->name('warehouses.stock-history.data');
	Route::get('warehouses/stock-history-finished-goods', [WarehouseController::class, 'stockHistoryFinishedGoods'])->name('warehouses.stock-history-finished-goods');
	Route::get('warehouses/stock-history-finished-goods/data', [WarehouseController::class, 'getStockHistoryFinishedGoodsData'])->name('warehouses.stock-history-finished-goods.data');
	Route::get('warehouses/stock-history-raw-materials', [WarehouseController::class, 'stockHistoryRawMaterials'])->name('warehouses.stock-history-raw-materials');
	Route::get('warehouses/stock-history-raw-materials/data', [WarehouseController::class, 'getStockHistoryRawMaterialsData'])->name('warehouses.stock-history-raw-materials.data');
	Route::patch('warehouses/{warehouse}/toggle-active', [WarehouseController::class, 'toggleActive'])->name('warehouses.toggle-active');
	Route::resource('warehouses', WarehouseController::class);

	// BOM Pick List Management
	Route::prefix('warehouses/bom-pick-list')->name('warehouses.bom-pick-list.')->group(function () {
		Route::get('/', [WarehouseController::class, 'bomPickListIndex'])->name('index');
		Route::get('/create', [WarehouseController::class, 'bomPickListCreate'])->name('create');
		Route::post('/get-details', [WarehouseController::class, 'getManufacturingRunDetails'])->name('get-details');
		Route::get('/search-employees', [WarehouseController::class, 'searchEmployees'])->name('search-employees');
		Route::post('/store', [WarehouseController::class, 'storeBomPickList'])->name('store');
		Route::get('/data', [WarehouseController::class, 'getBomPickListData'])->name('data');
		Route::get('/{bomPickList}', [WarehouseController::class, 'showBomPickList'])->name('show');
		Route::put('/{bomPickList}/status', [WarehouseController::class, 'updateBomPickListStatus'])->name('update-status');
	});

	// Planned Manufacturing Runs Management (Warehouse Confirmation)
	Route::prefix('warehouses/planned-manufacturing')->name('warehouses.planned-manufacturing.')->group(function () {
		Route::get('/index', [WarehouseController::class, 'plannedManufacturingIndex'])->name('index');
		Route::get('/data', [WarehouseController::class, 'getPlannedManufacturingData'])->name('data');
		Route::post('/{manufacturingRun}/start', [WarehouseController::class, 'startPlannedManufacturing'])->name('start');
	});

	// Shops (no delete; toggle active)
	Route::patch('shops/{shop}/toggle-active', [ShopController::class, 'toggleActive'])->name('shops.toggle-active');
	Route::get('shops/search', [ShopController::class, 'search'])->name('shops.search');
	Route::resource('shops', ShopController::class)->except(['destroy', 'show']);

	// Shop Management Routes
	Route::prefix('shop')->name('shop.')->group(function () {
		Route::get('dashboard', [ShopController::class, 'dashboard'])->name('dashboard');
		Route::get('dashboard/pdf', [ShopController::class, 'dashboardPDF'])->name('dashboard.pdf');
		Route::get('products/data', [App\Http\Controllers\ShopProductController::class, 'getData'])->name('products.data');
		Route::resource('products', App\Http\Controllers\ShopProductController::class)->only(['index']);
		Route::get('transactions/data', [App\Http\Controllers\ShopTransactionController::class, 'getData'])->name('transactions.data');
		Route::resource('transactions', App\Http\Controllers\ShopTransactionController::class)->only(['index']);
		Route::get('transactions/expense/{code}', [App\Http\Controllers\ShopExpenseController::class, 'show'])->name('transactions.expense.show');
			Route::get('transactions/attachments/{attachment}/download', [App\Http\Controllers\ShopExpenseController::class, 'downloadAttachment'])->name('transactions.attachment.download');
			Route::get('transactions/attachments/{attachment}/view', [App\Http\Controllers\ShopExpenseController::class, 'viewAttachment'])->name('transactions.attachment.view');
		Route::get('contacts/data', [App\Http\Controllers\ShopContactController::class, 'getData'])->name('contacts.data');
		Route::resource('contacts', App\Http\Controllers\ShopContactController::class)->only(['index']);
		Route::get('contact-transactions/{contactCode}', [App\Http\Controllers\ShopContactController::class, 'contactTransactions'])->name('contact.transactions');
		Route::get('contact-transactions/data/{contactCode}', [App\Http\Controllers\ShopContactController::class, 'getContactTransactionsData'])->name('contact.transactions.data');
	});

	// API Routes for QC Module
    Route::post('qc', [App\Http\Controllers\Api\QcController::class, 'store'])->name('qc.store');
	Route::prefix('api')->name('api.')->group(function () {
		Route::get('qc/{qc}', [App\Http\Controllers\Api\QcController::class, 'show'])->name('qc.show');
		Route::get('igp/search', [App\Http\Controllers\Api\QcController::class, 'searchIgps'])->name('igp.search');
		Route::get('warehouse/{warehouse}/bins', [App\Http\Controllers\Api\QcController::class, 'getWarehouseBins'])->name('warehouse.bins');
		Route::get('igp/{igp}/items', [App\Http\Controllers\Api\QcController::class, 'getIgpItems'])->name('igp.items');
		Route::get('warehouses', [WarehouseController::class, 'getWarehousesForApi'])->name('warehouses.index');
	});

    Route::post('api/contacts', [App\Http\Controllers\Api\ContactController::class, 'store'])->name('api.contacts.store');

    // Employee routes
	Route::get('employees/data/{emplyeeId}', [App\Http\Controllers\EmployeeController::class, 'getData'])->name('employees.data');
    Route::resource('employees', App\Http\Controllers\EmployeeController::class);

    // Employee Attendance routes
    Route::prefix('employee-attendance')->name('employee-attendance.')->group(function () {
        Route::get('/', [App\Http\Controllers\EmployeeAttendanceController::class, 'index'])->name('index');
        Route::get('/create', [App\Http\Controllers\EmployeeAttendanceController::class, 'create'])->name('create');
        Route::post('/', [App\Http\Controllers\EmployeeAttendanceController::class, 'store'])->name('store');
        Route::post('/bulk', [App\Http\Controllers\EmployeeAttendanceController::class, 'bulkStore'])->name('bulk-store');
        Route::get('/summary', [App\Http\Controllers\EmployeeAttendanceController::class, 'summary'])->name('summary');
        Route::get('/{attendance}', [App\Http\Controllers\EmployeeAttendanceController::class, 'show'])->name('show');
        Route::put('/{attendance}', [App\Http\Controllers\EmployeeAttendanceController::class, 'update'])->name('update');
        Route::delete('/{attendance}', [App\Http\Controllers\EmployeeAttendanceController::class, 'destroy'])->name('destroy');
    });

    // Employee Payroll routes
    Route::prefix('employee-payroll')->name('employee-payroll.')->group(function () {
        Route::get('/', [App\Http\Controllers\EmployeePayrollController::class, 'index'])->name('index');
        Route::get('/create', [App\Http\Controllers\EmployeePayrollController::class, 'create'])->name('create');
        Route::post('/calculate', [App\Http\Controllers\EmployeePayrollController::class, 'calculate'])->name('calculate');
        Route::post('/bulk-calculate', [App\Http\Controllers\EmployeePayrollController::class, 'bulkCalculate'])->name('bulk-calculate');
        Route::get('/{payroll}', [App\Http\Controllers\EmployeePayrollController::class, 'show'])->name('show');
        Route::post('/{payroll}/recalculate', [App\Http\Controllers\EmployeePayrollController::class, 'recalculate'])->name('recalculate');
        Route::patch('/{payroll}/adjustments', [App\Http\Controllers\EmployeePayrollController::class, 'updateAdjustments'])->name('update-adjustments');
        Route::post('/{payroll}/approve', [App\Http\Controllers\EmployeePayrollController::class, 'approve'])->name('approve');
        Route::post('/{payroll}/mark-paid', [App\Http\Controllers\EmployeePayrollController::class, 'markAsPaid'])->name('mark-paid');
        Route::post('/{payroll}/cancel', [App\Http\Controllers\EmployeePayrollController::class, 'cancel'])->name('cancel');
        Route::delete('/{payroll}', [App\Http\Controllers\EmployeePayrollController::class, 'destroy'])->name('destroy');
    });

    Route::middleware(['auth'])->group(function () {
	// Factory POS Routes
    Route::get('factory-pos/items', [App\Http\Controllers\FactoryPOSController::class, 'getItems'])->name('factory-pos.items');
    Route::get('factory-pos/warehouses', [App\Http\Controllers\FactoryPOSController::class, 'getWarehouses'])->name('factory-pos.warehouses');
    Route::get('factory-pos/data', [App\Http\Controllers\FactoryPOSController::class, 'getData'])->name('factory-pos.data');
    Route::resource('factory-pos', App\Http\Controllers\FactoryPOSController::class)->except(['show'])  ;
    Route::get('factory-pos/invoice/{id}/show', [App\Http\Controllers\FactoryPOSController::class, 'invoiceShow'])->name('factory.pos.show');
    Route::get('factory-pos/{id}/show', [App\Http\Controllers\FactoryPOSController::class, 'show'])->name('factory-pos.show');
    Route::get('factory-pos/{id}/print', [App\Http\Controllers\FactoryPOSController::class, 'print'])->name('factory-pos.print');

    // Delivery Receipt Routes
    Route::resource('delivery-receipts', App\Http\Controllers\DeliveryReceiptController::class);
    Route::get('delivery-receipt/data', [App\Http\Controllers\DeliveryReceiptController::class, 'getData'])->name('delivery-receipts.data');
    Route::post('delivery-receipts/{receipt}/submit', [App\Http\Controllers\DeliveryReceiptController::class, 'submit'])->name('delivery-receipts.submit');
    Route::post('delivery-receipts/{receipt}/process', [App\Http\Controllers\DeliveryReceiptController::class, 'process'])->name('delivery-receipts.process');
    Route::get('delivery-receipts/gate-pass/{gatePass}/items', [App\Http\Controllers\DeliveryReceiptController::class, 'getGatePassItems'])->name('delivery-receipts.gate-pass-items');
    Route::get('delivery-receipts/customers', [App\Http\Controllers\DeliveryReceiptController::class, 'getCustomers'])->name('delivery-receipts.customers');

});
    // Warehouse Factory Invoice Routes
    Route::prefix('warehouse')->name('warehouse.')->group(function () {
        Route::get('factory-invoices', [App\Http\Controllers\WarehouseController::class, 'pendingFactoryInvoices'])->name('factory-invoices.index');
        Route::get('factory-invoices/data', [App\Http\Controllers\WarehouseController::class, 'getPendingFactoryInvoices'])->name('factory-invoices.data');
        Route::get('factory-invoices/{invoice}/confirm', [App\Http\Controllers\WarehouseController::class, 'confirmFactoryInvoicePicking'])->name('factory-invoices.confirm');
        Route::post('factory-invoices/{invoice}/process', [App\Http\Controllers\WarehouseController::class, 'processFactoryInvoicePicking'])->name('factory-invoices.process');
    });

    // API routes for employee forms
    Route::get('api/shops', function() {
        return \App\Models\Account::where('model_type', 'shop')->select('id', 'name')->get();
    });

    // Shop API routes for modals
    Route::prefix('api/shop')->name('api.shop.')->group(function () {
        Route::get('contact-info', [App\Http\Controllers\Api\ShopApiController::class, 'getContactInfo'])->name('contact-info');
        Route::get('employee-info', [App\Http\Controllers\Api\ShopApiController::class, 'getEmployeeInfo'])->name('employee-info');
        Route::get('invoice-info', [App\Http\Controllers\Api\ShopApiController::class, 'getInvoiceInfo'])->name('invoice-info');
        Route::get('goods-receipt-info', [App\Http\Controllers\Api\ShopApiController::class, 'getGoodsReceiptInfo'])->name('goods-receipt-info');
        Route::get('invoice-return-info', [App\Http\Controllers\Api\ShopApiController::class, 'getInvoiceReturnInfo'])->name('invoice-return-info');
        Route::get('contact-transactions', [App\Http\Controllers\Api\ShopApiController::class, 'getContactTransactions'])->name('contact-transactions');
        Route::get('invoice-pdf/{invoiceCode}/{shopId}', [App\Http\Controllers\Api\ShopApiController::class, 'downloadInvoicePDF'])->name('invoice-pdf');
        Route::get('goods-receipt-pdf/{receiptCode}/{shopId}', [App\Http\Controllers\Api\ShopApiController::class, 'downloadGoodsReceiptPDF'])->name('goods-receipt-pdf');
        Route::get('invoice-return-pdf/{returnCode}/{shopId}', [App\Http\Controllers\Api\ShopApiController::class, 'downloadInvoiceReturnPDF'])->name('invoice-return-pdf');
        Route::get('contact-pdf/{contactCode}/{shopId}', [App\Http\Controllers\Api\ShopApiController::class, 'downloadContactPDF'])->name('contact-pdf');
    });
});

// Manufacturing Routes
Route::middleware(['auth', 'verified'])->group(function () {
    Route::prefix('manufacturing')->name('manufacturing.')->group(function () {
        // Start Manufacturing
        Route::get('start', [App\Http\Controllers\ManufacturingController::class, 'startManufacturingForm'])->name('start');
        Route::post('start', [App\Http\Controllers\ManufacturingController::class, 'startManufacturing'])->name('start.store');

        // Conclude Manufacturing
        Route::get('conclude/{manufacturingRun}', [App\Http\Controllers\ManufacturingController::class, 'concludeManufacturing'])->name('conclude');
        Route::post('conclude/{manufacturingRun}', [App\Http\Controllers\ManufacturingController::class, 'concludeManufacturingStore'])->name('conclude.store');

                    // Manufacturing Runs
                    Route::get('runs', [App\Http\Controllers\ManufacturingController::class, 'runsIndex'])->name('runs.index');
                    // Route::get('runs/{id}', [App\Http\Controllers\ManufacturingController::class, 'showRun'])->name('runs.show');
                    Route::get('runs/{id}/download-pdf', [App\Http\Controllers\ManufacturingController::class, 'downloadPDF'])->name('runs.download-pdf');
                    Route::get('runs/{id}/download-pdf/{pageSize}', [App\Http\Controllers\ManufacturingController::class, 'downloadPDFWithSize'])->name('runs.download-pdf-size');

                    // Cost of Production
                    Route::get('cost-of-production', [App\Http\Controllers\CostOfProductionController::class, 'index'])->name('cost-of-production.index');
                    Route::post('cost-of-production/calculate', [App\Http\Controllers\CostOfProductionController::class, 'calculate'])->name('cost-of-production.calculate');
                    Route::get('cost-of-production/history', [App\Http\Controllers\CostOfProductionController::class, 'history'])->name('cost-of-production.history');

                    // Cost Centers Management
                    Route::get('cost-centers', [App\Http\Controllers\CostCenterController::class, 'index'])->name('cost-centers.index');
    });
    Route::get('manufacturing-runs/{id}', [App\Http\Controllers\ManufacturingController::class, 'showRun'])->name('manufacturing.runs.show');

});

// API Routes for Chart of Accounts
Route::prefix('api')->group(function () {
    Route::get('chart-of-accounts/hierarchy', [App\Http\Controllers\Api\ChartOfAccountController::class, 'getHierarchyWithAccounts'])->name('api.chart-of-accounts.hierarchy');
    Route::get('chart-of-accounts/{id}/hierarchy', [App\Http\Controllers\Api\ChartOfAccountController::class, 'getChartOfAccountHierarchy'])->name('api.chart-of-accounts.hierarchy.specific');
    Route::get('chart-of-accounts/all', [App\Http\Controllers\Api\ChartOfAccountController::class, 'getAllWithAccounts'])->name('api.chart-of-accounts.all');
});

	// API Routes for Cost Centers
	Route::prefix('api')->group(function () {
		Route::get('cost-centers/form-data', [App\Http\Controllers\Api\CostCenterController::class, 'getFormData'])->name('api.cost-centers.form-data');
		Route::get('cost-centers/finished-goods', [App\Http\Controllers\Api\CostCenterController::class, 'getFinishedGoods'])->name('api.cost-centers.finished-goods');
		Route::get('cost-centers/{itemId}/assignments', [App\Http\Controllers\Api\CostCenterController::class, 'getCostCentersForItem'])->name('api.cost-centers.assignments');
		Route::post('cost-centers/assignments', [App\Http\Controllers\Api\CostCenterController::class, 'updateAssignments'])->name('api.cost-centers.update-assignments');
		Route::get('cost-centers/{itemId}/history', [App\Http\Controllers\Api\CostCenterController::class, 'getHistory'])->name('api.cost-centers.history');

		// Payment and Receipt API Routes
		Route::get('get-references', [App\Http\Controllers\Api\PaymentController::class, 'getReferences'])->name('api.get-references');
		Route::post('process-payment', [App\Http\Controllers\Api\PaymentController::class, 'processPayment'])->name('api.process-payment');
		Route::post('process-receipt', [App\Http\Controllers\Api\PaymentController::class, 'processReceipt'])->name('api.process-receipt');
	});

// Desktop API Routes
Route::prefix('api/desktop')->group(function () {
    // Public routes (no authentication required)
    Route::get('check-license', [LicenseAPIController::class, 'checkLicense'])->name('api.desktop.check-license');
    Route::post('authenticate', [APIAuthController::class, 'authenticate'])
    ->name('api.desktop.authenticate');

    Route::prefix('sync')->group(function () {
        Route::get('app-launch', [SyncAPIController::class, 'appLaunchSync'])->name('api.desktop.app-launch-sync');

        // Attachment sync (public - authenticated by license_key + shop_id, NOT a bearer token)
        Route::post('attachments/upload', [AttachmentSyncController::class, 'upload'])->name('api.desktop.sync.attachments.upload');
        Route::get('attachments/download', [AttachmentSyncController::class, 'download'])->name('api.desktop.sync.attachments.download');

        Route::middleware(['auth:sanctum', 'shop.isolation'])->group(function () {

            // Sync routes - Push (Local → Server)
            Route::prefix('push')->group(function () {
                Route::post('user-password-changes', [PushController::class, 'pushUserPasswordChanges'])->name('api.desktop.push.user-password-changes');
                Route::post('product-updates', [PushController::class, 'pushProductUpdates'])->name('api.desktop.push.product-updates');
                Route::post('new-products', [PushController::class, 'pushNewProducts'])->name('api.desktop.push.new-products');
                Route::post('products', [PushController::class, 'pushProducts'])->name('api.desktop.push.shop-products');
                Route::post('customer-edits', [PushController::class, 'pushCustomerEdits'])->name('api.desktop.push.customer-edits');
                Route::post('new-customers', [PushController::class, 'pushNewCustomers'])->name('api.desktop.push.new-customers');
                Route::post('customer-account-updates', [PushController::class, 'pushCustomerAccountUpdates'])->name('api.desktop.push.customer-account-updates');
                Route::post('stock-entries', [PushController::class, 'pushStockEntries'])->name('api.desktop.push.stock-entries');
                Route::post('invoices', [PushController::class, 'pushInvoices'])->name('api.desktop.push.invoices');
                Route::post('invoice-items', [PushController::class, 'pushInvoiceItems'])->name('api.desktop.push.invoice-items');
                Route::post('invoice-returns', [PushController::class, 'pushInvoiceReturns'])->name('api.desktop.push.invoice-returns');
                Route::post('invoice-return-items', [PushController::class, 'pushInvoiceReturnItems'])->name('api.desktop.push.invoice-return-items');
                Route::post('goods-receipts', [PushController::class, 'pushGoodsReceipts'])->name('api.desktop.push.goods-receipts');
                Route::post('goods-receipt-items', [PushController::class, 'pushGoodsReceiptItems'])->name('api.desktop.push.goods-receipt-items');
                Route::post('contacts', [PushController::class, 'pushContacts'])->name('api.desktop.push.contacts');
                Route::post('stocks', [PushController::class, 'pushStocks'])->name('api.desktop.push.stocks');
                Route::post('contact-account-transactions', [PushController::class, 'pushContactAccountTransactions'])->name('api.desktop.push.contact-account-transactions');
                Route::post('return-invoices', [PushController::class, 'pushReturnInvoices'])->name('api.desktop.push.return-invoices');
                Route::post('expense-categories', [PushController::class, 'pushExpenseCategories'])->name('api.desktop.push.expense-categories');
            });

            // Sync routes - Pull (Server → Local)
            Route::prefix('pull')->group(function () {
                Route::get('user-info', [PullController::class, 'pullUserInfo'])->name('api.desktop.pull.user-info');
                Route::get('employee-info', [PullController::class, 'pullEmployeeInfo'])->name('api.desktop.pull.employee-info');
                Route::get('product-updates', [PullController::class, 'pullProductUpdates'])->name('api.desktop.pull.product-updates');
                // Route::post('new-products', [PullController::class, 'pullNewProducts'])->name('api.desktop.pull.new-products');
                Route::post('products', [PullController::class, 'pullProducts'])->name('api.desktop.pull.products');
                Route::post('products/mark-synced', [PullController::class, 'markSynced'])->name('api.desktop.pull.products.mark-synced');
                Route::get('customer-info', [PullController::class, 'pullCustomerInfo'])->name('api.desktop.pull.customer-info');
                // Alias for client apps using /customers
                Route::get('customers', [PullController::class, 'pullCustomerInfo'])->name('api.desktop.pull.customers');
                Route::get('contacts', [PullController::class, 'pullShopContacts'])->name('api.desktop.pull.shop-contacts');
                Route::get('customer-account-updates', [PullController::class, 'pullCustomerAccountUpdates'])->name('api.desktop.pull.customer-account-updates');
                Route::get('product-stock', [PullController::class, 'pullProductStock'])->name('api.desktop.pull.product-stock');
                Route::get('server-changes', [PullController::class, 'pullServerChanges'])->name('api.desktop.pull.server-changes');
                Route::get('invoices', [PullController::class, 'pullInvoices'])->name('api.desktop.pull.invoices');
                Route::get('invoice-items', [PullController::class, 'pullInvoiceItems'])->name('api.desktop.pull.invoice-items');
                Route::get('invoice-return-items', [PullController::class, 'pullInvoiceReturnItems'])->name('api.desktop.pull.invoice-return-items');
                Route::get('contact-account-transactions', [PullController::class, 'pullContactAccountTransactions'])->name('api.desktop.pull.contact-account-transactions');
                Route::get('goods-receipts', [PullController::class, 'pullGoodsReceipts'])->name('api.desktop.pull.goods-receipts');
                Route::get('goods-receipt-items', [PullController::class, 'pullGoodsReceiptItems'])->name('api.desktop.pull.goods-receipt-items');
                Route::get('stocks', [PullController::class, 'pullStocks'])->name('api.desktop.pull.stocks');
                Route::get('invoice-returns', [PullController::class, 'pullInvoiceReturns'])->name('api.desktop.pull.invoice-returns');
                Route::get('expense-categories', [PullController::class, 'pullExpenseCategories'])->name('api.desktop.pull.expense-categories');
            });
        });
    });

    // Protected routes (require Sanctum authentication)

})->withoutMiddleware('web');

require __DIR__.'/auth.php';
