<?php

use Illuminate\Support\Facades\Route;
use Modules\User\Http\Controllers\UserController;
use App\Http\Controllers\ImpersonateController;
use Modules\User\Http\Controllers\AddressController;
use Modules\User\Http\Controllers\EmploymentController;
use Modules\User\Http\Controllers\BankController;
use Modules\User\Http\Controllers\BankDetailController;
use Modules\User\Http\Controllers\HeirController;

Route::middleware(['auth:sanctum', 'single.session'])->prefix('v1')->group(function () {
    Route::get('users/deleted', [UserController::class, 'deletedIndex'])->name('users.deleted.index');
    Route::post('users/{id}/restore', [UserController::class, 'restore'])->name('users.restore');
    Route::apiResource('users', UserController::class)->names('user');
    Route::apiResource('addresses', AddressController::class)->names('address');
    // employement
    Route::apiResource('employments', EmploymentController::class)->names('employment');
    // bank and bank detail
    Route::get('banks/active', [BankController::class, 'active'])->name('bank.active');
    Route::apiResource('banks', BankController::class)->names('bank');
    Route::apiResource('bank_details', BankDetailController::class)->names('bank_detail');
    // heir
    Route::apiResource('heirs', HeirController::class)->names('heir');
    // User role management routes
    Route::post('users/{user}/roles', [UserController::class, 'assignRoles'])->name('users.roles.assign');

    // User profile management routes
    Route::post('/profile', [UserController::class, 'updateProfile']);
    Route::put('/profile/password', [UserController::class, 'updatePassword']);
    
    // Impersonation routes
    Route::get('/impersonate/take/{id}', [ImpersonateController::class, 'take'])->name('impersonate');
    Route::get('/impersonate/leave', [ImpersonateController::class, 'leave'])->name('impersonate.leave');
    Route::get('/impersonate/status', [ImpersonateController::class, 'status'])->name('impersonate.status');
});
