<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Landlord\DashboardController;
use App\Http\Controllers\Landlord\TenantController;
use App\Http\Controllers\Landlord\ProfileController;

/*
|--------------------------------------------------------------------------
| Landlord Routes (房東後台路由)
|--------------------------------------------------------------------------
|
| 這些路由用於中央管理後台，只能透過 central domain 存取。
| 用於管理租戶 (新增、編輯、停用) 等系統級操作。
|
*/

Route::prefix('landlord')->name('landlord.')->middleware(['web', 'auth', \App\Http\Middleware\PreventAccessFromTenantDomains::class])->group(function () {
    // 房東儀表板
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
    
    // 租戶管理 CRUD
    Route::resource('tenants', TenantController::class);
    
    // 使用者設定
    Route::get('profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::put('profile/password', [ProfileController::class, 'updatePassword'])->name('profile.password');
    
    // 租戶域名管理
    Route::post('tenants/{tenant}/domains', [TenantController::class, 'addDomain'])->name('tenants.domains.store');
    Route::delete('tenants/{tenant}/domains/{domain}', [TenantController::class, 'removeDomain'])->name('tenants.domains.destroy');
    
    // 租戶樣式管理
    Route::get('tenants/{tenant}/branding', [TenantController::class, 'showBranding'])->name('tenants.branding');
    Route::post('tenants/{tenant}/branding', [TenantController::class, 'updateBranding'])->name('tenants.branding.update');

    // 租戶 API Token 管理
    Route::post('tenants/{tenant}/tokens', [TenantController::class, 'createToken'])->name('tenants.tokens.store');
    Route::delete('tenants/{tenant}/tokens/{token}', [TenantController::class, 'revokeToken'])->name('tenants.tokens.destroy');
});
