<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\BookingController;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\JobController;
use App\Http\Controllers\MasterController;
use App\Http\Controllers\AuthController;

// Authentication Routes
Route::get('login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('login', [AuthController::class, 'login'])->name('login.post');
Route::post('logout', [AuthController::class, 'logout'])->name('logout');

// Protected Routes
Route::middleware('auth')->group(function () {
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');

    Route::resource('bookings', BookingController::class);
    Route::patch('bookings/{booking}/status', [BookingController::class, 'updateStatus'])->name('bookings.status');

    Route::resource('customers', CustomerController::class)->except(['create', 'edit', 'show']);
    Route::patch('customers/{customer}/status', [CustomerController::class, 'toggleStatus'])->name('customers.status');

    Route::get('jobs', [JobController::class, 'index'])->name('jobs.index');
    Route::get('jobs/{job}', [JobController::class, 'show'])->name('jobs.show');
    Route::patch('jobs/{job}/status', [JobController::class, 'updateStatus'])->name('jobs.status');

    Route::prefix('master')->name('master.')->group(function () {
        Route::get('{slug}', [MasterController::class, 'index'])->name('index');
        Route::post('{slug}', [MasterController::class, 'store'])->name('store');
        Route::put('{slug}/{id}', [MasterController::class, 'update'])->name('update');
        Route::delete('{slug}/{id}', [MasterController::class, 'destroy'])->name('destroy');
        Route::patch('{slug}/{id}/status', [MasterController::class, 'toggleStatus'])->name('status');
    });
});
