<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\SocialAccountController;
use App\Http\Controllers\PostController;
use App\Http\Controllers\AdminController;

/*
|--------------------------------------------------------------------------
| Guest Routes
|--------------------------------------------------------------------------
*/
Route::middleware('guest')->group(function () {
    Route::get('/', function () {
        return redirect()->route('login');
    });

    Route::get('/register', [AuthController::class, 'showRegister'])->name('register');
    Route::post('/register', [AuthController::class, 'register']);

    Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [AuthController::class, 'login']);
});

/*
|--------------------------------------------------------------------------
| Authenticated Routes
|--------------------------------------------------------------------------
*/
Route::middleware('auth')->group(function () {
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

    // Dashboard
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    // Social Accounts
    Route::resource('accounts', SocialAccountController::class)->except(['show']);

    // Posts
    Route::resource('posts', PostController::class);
    Route::post('/posts/{post}/publish-now', [PostController::class, 'publishNow'])
        ->name('posts.publish-now');
});

/*
|--------------------------------------------------------------------------
| Admin Routes
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'admin'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('dashboard');
    Route::get('/users', [AdminController::class, 'users'])->name('users');
    Route::post('/users/{user}/toggle-role', [AdminController::class, 'toggleUserRole'])
        ->name('users.toggle-role');
    Route::delete('/users/{user}', [AdminController::class, 'deleteUser'])
        ->name('users.destroy');
    Route::get('/posts', [AdminController::class, 'posts'])->name('posts');
    Route::post('/posts/{post}/force-publish', [AdminController::class, 'forcePublish'])
        ->name('posts.force-publish');
    Route::delete('/posts/{post}', [AdminController::class, 'deletePost'])
        ->name('posts.destroy');
    Route::get('/logs', [AdminController::class, 'activityLogs'])->name('logs');
});
