<?php

use App\Http\Controllers\AlbumController;
use App\Http\Controllers\ArtistController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\GenreController;
use App\Http\Controllers\LabelController;
use App\Http\Controllers\LikeController;
use App\Http\Controllers\TrackController;
use App\Http\Controllers\UploadController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;

Route::post('/register', [AuthController::class, 'register']);
Route::post('/login', [AuthController::class, 'login']);

Route::middleware('auth:sanctum')->group(function () {

    Route::post('/logout', [AuthController::class, 'logout']);
    Route::get('/me', [AuthController::class, 'me']);

    Route::get('/me/likes', [LikeController::class, 'index']);
    Route::post('/tracks/{track}/like', [LikeController::class, 'like']);
    Route::delete('/tracks/{track}/like', [LikeController::class, 'unlike']);

    Route::get('/labels', [LabelController::class,  'index']);
    Route::get('/labels/{label}', [LabelController::class,  'show']);
    Route::get('/genres', [GenreController::class,  'index']);
    Route::get('/genres/{genre}', [GenreController::class,  'show']);
    Route::get('/artists', [ArtistController::class, 'index']);
    Route::get('/artists/{artist}', [ArtistController::class, 'show']);
    Route::get('/albums', [AlbumController::class,  'index']);
    Route::get('/albums/{album}', [AlbumController::class,  'show']);
    Route::get('/tracks', [TrackController::class,  'index']);
    Route::get('/tracks/{track}', [TrackController::class,  'show']);

    Route::middleware('admin')->group(function () {

        Route::post('/labels', [LabelController::class,  'store']);
        Route::put('/labels/{label}', [LabelController::class,  'update']);
        Route::delete('/labels/{label}', [LabelController::class,  'destroy']);

        Route::post('/genres', [GenreController::class,  'store']);
        Route::put('/genres/{genre}', [GenreController::class,  'update']);
        Route::delete('/genres/{genre}', [GenreController::class,  'destroy']);

        Route::post('/artists', [ArtistController::class, 'store']);
        Route::put('/artists/{artist}', [ArtistController::class, 'update']);
        Route::delete('/artists/{artist}', [ArtistController::class, 'destroy']);

        Route::post('/albums', [AlbumController::class,  'store']);
        Route::put('/albums/{album}', [AlbumController::class,  'update']);
        Route::delete('/albums/{album}', [AlbumController::class,  'destroy']);

        Route::post('/tracks', [TrackController::class,  'store']);
        Route::put('/tracks/{track}', [TrackController::class,  'update']);
        Route::delete('/tracks/{track}', [TrackController::class,  'destroy']);

        Route::put('/albums/{album}/tracks/reorder', [TrackController::class, 'reorder']);

        Route::post('/upload/image', [UploadController::class, 'image']);
        Route::post('/upload/audio', [UploadController::class, 'audio']);

        Route::get('/users', [UserController::class,   'index']);
        Route::get('/users/{user}', [UserController::class,   'show']);
        Route::put('/users/{user}', [UserController::class,   'update']);
        Route::delete('/users/{user}', [UserController::class,   'destroy']);
    });
});
