<?php

use App\Http\Controllers\AuthController;
use App\Http\Controllers\DeviceTokenController;
use App\Http\Controllers\MealImageAnalysisController;
use App\Http\Controllers\MealPostController;
use App\Http\Controllers\PostReviewsController;
use App\Http\Controllers\StravaController;
use App\Http\Controllers\WorkoutSessionController;
use Illuminate\Support\Facades\Route;

// Auth
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::delete('me', [AuthController::class, 'destroy']);
    });

});

// Health
Route::get('/health', function () {
    return response()->json(['status' => 'ok']);
});
Route::middleware('auth:sanctum')->group(function (): void {
    Route::post('device-tokens', [DeviceTokenController::class, 'store']);
    Route::delete('device-tokens', [DeviceTokenController::class, 'destroy']);
    Route::get('test-notifs', [DeviceTokenController::class, 'notifs']);
});

// Workouts
Route::middleware('auth:sanctum')->group(function (): void {
    Route::get('workouts', [WorkoutSessionController::class, 'index'])->name('workouts.index');
    Route::post('workouts', [WorkoutSessionController::class, 'store'])->name('workouts.store');
    Route::get('strava/status', [StravaController::class, 'status'])->name('strava.status');
    Route::get('strava/authorization-url', [StravaController::class, 'authorizationUrl'])->name('strava.authorization-url');
    Route::post('strava/callback', [StravaController::class, 'callback'])->name('strava.callback');
    Route::post('strava/sync', [StravaController::class, 'sync'])->name('strava.sync');
});

// Meals
Route::middleware('auth:sanctum')->group(function (): void {
    Route::get('meal-posts/stats', [MealPostController::class, 'stats']);
    Route::get('meal-posts/calendar', [MealPostController::class, 'calendar']);
    Route::post('meal-posts/analyze-image', [MealImageAnalysisController::class, 'store']);
    Route::post('meal-posts/{mealPost}/like', [MealPostController::class, 'like'])->name('meal-posts.like');
    Route::delete('meal-posts/{mealPost}/like', [MealPostController::class, 'unlike'])->name('meal-posts.unlike');
    Route::get('meal-posts/{mealPost}/reviews', [PostReviewsController::class, 'index'])->name('meal-posts.reviews.index');
    Route::post('meal-posts/{mealPost}/reviews', [PostReviewsController::class, 'store'])->name('meal-posts.reviews.store');
    Route::get('post-reviews/{postReview}', [PostReviewsController::class, 'show'])->name('post-reviews.show');
    Route::put('post-reviews/{postReview}', [PostReviewsController::class, 'update'])->name('post-reviews.update');
    Route::patch('post-reviews/{postReview}', [PostReviewsController::class, 'update'])->name('post-reviews.patch');
    Route::delete('post-reviews/{postReview}', [PostReviewsController::class, 'destroy'])->name('post-reviews.destroy');
    Route::apiResource('meal-posts', MealPostController::class)->except(['update']);
    Route::put('meal-posts/{mealPost}', [MealPostController::class, 'update'])->name('meal-posts.update');
    Route::patch('meal-posts/{mealPost}', [MealPostController::class, 'update'])->name('meal-posts.patch');
});
