<?php

use Illuminate\Support\Facades\Route;
use App\Modules\PLATFORM\Settings\Http\Controllers\BranchSelectorController;
use App\Modules\PLATFORM\Settings\Http\Controllers\CountryController;
use App\Modules\PLATFORM\Settings\Http\Controllers\CurrencyController;
use App\Modules\PLATFORM\Settings\Http\Controllers\TimeZoneController;
use App\Modules\PLATFORM\Settings\Http\Controllers\StateController;
use App\Modules\PLATFORM\Settings\Http\Controllers\CityController;
use App\Modules\PLATFORM\Settings\Http\Controllers\CompanyController;
use App\Modules\PLATFORM\Settings\Http\Controllers\BranchController;
use App\Modules\PLATFORM\Settings\Http\Controllers\BankController;
use App\Modules\PLATFORM\Settings\Http\Controllers\BankBranchController;
use App\Modules\PLATFORM\Settings\Http\Controllers\PaymentMethodController;
use App\Modules\PLATFORM\Settings\Http\Controllers\DocumentTypeController;
use App\Modules\PLATFORM\UserManagement\Http\Controllers\RoleController;
use App\Modules\PLATFORM\UserManagement\Http\Controllers\UserController;

Route::middleware(['auth','branch','module:settings'])
    ->prefix('settings')
    ->name('settings.')
    ->group(function () {

        /*
        |--------------------------------------------------------------------------
        | LOCATION & REGION
        |--------------------------------------------------------------------------
        */
        Route::resource('countries', CountryController::class);
        Route::post('countries/{country}/status', [CountryController::class, 'status'])
            ->name('countries.status');

        Route::resource('states', StateController::class);
        Route::post('states/{state}/status', [StateController::class, 'status'])
            ->name('states.status');

        Route::resource('cities', CityController::class);
        Route::post('cities/{city}/status', [CityController::class, 'status'])
            ->name('cities.status');

        // Dependent dropdown
        Route::get('states/by-country/{country}', [CityController::class, 'statesByCountry'])
            ->name('states.by-country');

        /*
        |--------------------------------------------------------------------------
        | GLOBAL SETTINGS
        |--------------------------------------------------------------------------
        */
        Route::resource('currencies', CurrencyController::class);
        Route::post('currencies/{currency}/status', [CurrencyController::class, 'status'])
            ->name('currencies.status');

        Route::resource('time-zones', TimeZoneController::class);
        Route::post('time-zones/{time_zone}/status', [TimeZoneController::class, 'status'])
            ->name('time-zones.status');

        /*
        |--------------------------------------------------------------------------
        | ORGANIZATION
        |--------------------------------------------------------------------------
        */
        Route::resource('companies', CompanyController::class);
        Route::post('companies/{company}/status', [CompanyController::class, 'status'])
            ->name('companies.status');

        Route::resource('branches', BranchController::class);
        Route::post('branches/{branch}/status', [BranchController::class, 'status'])
            ->name('branches.status');

        /*
        |--------------------------------------------------------------------------
        | FINANCIAL & PAYMENT
        |--------------------------------------------------------------------------
        */
        Route::resource('banks', BankController::class);
        Route::post('banks/{bank}/status', [BankController::class, 'status'])
            ->name('banks.status');

        Route::resource('bank-branches', BankBranchController::class);
        Route::post('bank-branches/{bank_branch}/status', [BankBranchController::class, 'status'])
            ->name('bank-branches.status');

        Route::resource('payment-methods', PaymentMethodController::class);
        Route::post('payment-methods/{payment_method}/status', [PaymentMethodController::class, 'status'])
            ->name('payment-methods.status');

        Route::resource('document-types', DocumentTypeController::class);

        /*
        |--------------------------------------------------------------------------
        | ACCESS CONTROL
        |--------------------------------------------------------------------------
        */
        Route::resource('roles', RoleController::class);
        Route::resource('users', UserController::class);
    });


    // Branch Selection Routes (no prefix, accessible to all authenticated users)
Route::middleware(['auth'])->group(function () {
    Route::get('/branch/select', [BranchSelectorController::class, 'show'])
        ->name('branch.select');
    
    Route::post('/branch/select', [BranchSelectorController::class, 'select'])
        ->name('branch.select.post');
    
    Route::post('/branch/switch', [BranchSelectorController::class, 'switch'])
        ->name('branch.switch');
});
