<?php

use App\Http\Controllers\CcliPasteController;
use App\Http\Controllers\ProFileController;
use App\Http\Controllers\ServiceSongController;
use App\Http\Controllers\SongController;
use App\Http\Controllers\TranslationController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routen
|--------------------------------------------------------------------------
|
| Alle API-Routen sind authentifizierungspflichtig und verwenden
| das Prefix /api automatisch durch die Laravel API-Routing-Konvention.
|
*/

Route::middleware('auth:sanctum')->group(function () {
    Route::apiResource('songs', SongController::class)->names('api.songs');

    Route::post('/service-songs/{serviceSongId}/assign', [ServiceSongController::class, 'assignSong'])
        ->name('api.service-songs.assign');

    Route::post('/service-songs/{serviceSongId}/request', [ServiceSongController::class, 'requestSong'])
        ->name('api.service-songs.request');

    Route::post('/service-songs/{serviceSongId}/unassign', [ServiceSongController::class, 'unassign'])
        ->name('api.service-songs.unassign');

    Route::post('/service-songs/{serviceSongId}/confirm', [ServiceSongController::class, 'confirm'])
        ->name('api.service-songs.confirm');

    Route::post('/service-songs/{serviceSongId}/unconfirm', [ServiceSongController::class, 'unconfirm'])
        ->name('api.service-songs.unconfirm');

    Route::patch('/service-songs/{serviceSongId}', [ServiceSongController::class, 'update'])
        ->name('api.service-songs.update');

    // Übersetzung
    Route::post('/translation/fetch-url', [TranslationController::class, 'fetchUrl'])
        ->name('api.translation.fetch-url');

    Route::post('/songs/{song}/translation/import', [TranslationController::class, 'import'])
        ->name('api.songs.translation.import');

    Route::delete('/songs/{song}/translation', [TranslationController::class, 'destroy'])
        ->name('api.songs.translation.destroy');

    // .pro Datei Upload und Download (Placeholder)
    Route::post('/songs/import-pro', [ProFileController::class, 'importPro'])
        ->name('api.songs.import-pro');

    Route::get('/songs/{song}/download-pro', [ProFileController::class, 'downloadPro'])
        ->name('api.songs.download-pro');

    // CCLI Paste Import (manuelles Einfügen oder Bookmarklet)
    Route::middleware('throttle:30,1')->group(function () {
        Route::post('/ccli/preview', [CcliPasteController::class, 'preview'])
            ->name('api.ccli.preview');
        Route::post('/songs/import-from-ccli-paste', [CcliPasteController::class, 'importPaste'])
            ->name('api.ccli.import');
    });
});
