<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Broadcast;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\todoController;
Route::prefix('auth')->group(function (): void {
    Route::post('register', [AuthController::class, 'register']);
    Route::post('login', [AuthController::class, 'login']);
    Route::middleware('auth:sanctum')->group(function (): void {
        Route::post('logout', [AuthController::class, 'logout']);
        Route::get('me', [AuthController::class, 'me']);
        Route::patch('me', [AuthController::class, 'update']);
    });

});
Route::middleware('auth:sanctum')->prefix('todos')->group(function (): void {
    Route::get('/', [todoController::class, 'index']);
    Route::post('/', [todoController::class, 'store']);
    Route::get('/{todo}', [todoController::class, 'show']);
    Route::patch('/{todo}', [todoController::class, 'update']);
    Route::delete('/{todo}', [todoController::class, 'destroy']);
});

Route::middleware('auth:sanctum')->group(function (): void {
    Broadcast::routes();
    Route::get('users', [\App\Http\Controllers\UserController::class, 'index']);
    Route::apiResource('conversations', \App\Http\Controllers\ConversationController::class);
    
    Route::get('conversations/{conversation}/messages', [\App\Http\Controllers\MessageController::class, 'index']);
    Route::post('conversations/{conversation}/messages', [\App\Http\Controllers\MessageController::class, 'store']);
    
    Route::delete('messages/{message}', [\App\Http\Controllers\MessageController::class, 'destroy']);
    Route::patch('messages/{message}/read', [\App\Http\Controllers\MessageController::class, 'markAsRead']);
});
