<?php

use App\Http\Controllers\Admin\AlertController;
use App\Http\Controllers\Admin\CommentsController;
use App\Http\Controllers\Admin\ContactController;
use App\Http\Controllers\Admin\EpisodeController;
use App\Http\Controllers\Admin\ReleaseController;
use App\Http\Controllers\Admin\SiteBackgroundController;
use App\Http\Controllers\Admin\SubtitleController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Api\AdminApiController;
use Illuminate\Support\Facades\Route;

/*
|---------------------------------------------------------------------------------
| Admin Routes
|---------------------------------------------------------------------------------
*/
Route::group(['middleware' => ['auth', 'auth.admin']], function () {
    // Site alerts
    Route::get('/admin/alert', [AlertController::class, 'index'])->name('admin.alert.index');
    Route::post('/admin/alert', [AlertController::class, 'store'])->name('admin.alert.create');
    Route::delete('/admin/alert/{alert_id}', [AlertController::class, 'delete'])->name('admin.alert.delete');

    // Users
    Route::get('/admin/users', [UserController::class, 'index'])->name('admin.user.index');
    Route::post('/admin/users', [UserController::class, 'update'])->name('admin.user.update');

    // Comments
    Route::get('/admin/comments', [CommentsController::class, 'index'])->name('admin.comments.index');

    // Contact page overview
    Route::get('/admin/contact', [ContactController::class, 'index'])->name('admin.contact.index');
    Route::delete('/admin/contact/{contact_id}', [ContactController::class, 'delete'])->name('admin.contact.delete');

    // Site background settings
    Route::get('/admin/background', [SiteBackgroundController::class, 'index'])->name('admin.background.index');
    Route::post('/admin/background', [SiteBackgroundController::class, 'create'])->name('admin.background.create');
    Route::put('/admin/background', [SiteBackgroundController::class, 'update'])->name('admin.background.update');
    Route::delete('/admin/background', [SiteBackgroundController::class, 'delete'])->name('admin.background.delete');

    // Release
    Route::get('/admin/release', [ReleaseController::class, 'index'])->name('admin.upload.index');
    Route::post('/admin/release/upload', [ReleaseController::class, 'store'])->name('admin.upload');

    // Episode
    Route::post('/admin/episode/upload', [EpisodeController::class, 'store'])->name('admin.upload.episode');
    Route::post('/admin/episode/edit', [EpisodeController::class, 'update'])->name('admin.edit');

    // Get Tags used for Upload Form
    Route::get('/admin/tags', [AdminApiController::class, 'getTags'])->name('admin.tags');
    Route::get('/admin/studios', [AdminApiController::class, 'getStudios'])->name('admin.studios');

    // Subtitles
    Route::get('/admin/subtitles/{episode_id}', [AdminApiController::class, 'getSubtitles'])->name('admin.subtitles');
    Route::post('/admin/add-new-subtitle', [SubtitleController::class, 'store'])->name('admin.add.new.subtitle');
    Route::post('/admin/update-subtitles', [SubtitleController::class, 'update'])->name('admin.update.subtitles');
});

/*
|---------------------------------------------------------------------------------
| Moderator Routes
|---------------------------------------------------------------------------------
*/
Route::group(['middleware' => ['auth', 'auth.moderator']], function () {
    // Get Tags for editing Episode
    Route::get('/admin/tags/{episode_id}', [AdminApiController::class, 'getEpisodeTags'])->name('admin.tags.episode');
    Route::get('/admin/studio/{episode_id}', [AdminApiController::class, 'getEpisodeStudio'])->name('admin.studio.episode');
});