<?php

use App\Http\Controllers\PublicController;
use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Advertiser\AdvertiserController;
use App\Http\Controllers\Advertiser\CartController;
use App\Http\Controllers\Owner\OwnerController;
use App\Http\Controllers\Owner\ProofController;
use App\Http\Controllers\DisputeController;
use App\Http\Controllers\Admin\AdminController;

// ============================================================
// Public routes
// ============================================================
Route::get('/', [PublicController::class, 'home'])->name('home');
Route::get('/explore', [PublicController::class, 'explore'])->name('explore');
Route::get('/placements/dooh/{placement}', [PublicController::class, 'placementDooh'])->name('placement.dooh');
Route::get('/placements/billboard/{placement}', [PublicController::class, 'placementBillboard'])->name('placement.billboard');

// ============================================================
// Auth routes (Breeze)
// ============================================================
require __DIR__.'/auth.php';

// ============================================================
// Authenticated routes
// ============================================================
Route::middleware('auth')->group(function () {

    // Profile
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');

    // ============================================================
    // Advertiser portal
    // ============================================================
    Route::prefix('advertiser')->name('advertiser.')->group(function () {
        Route::get('/dashboard', [AdvertiserController::class, 'dashboard'])->name('dashboard');
        Route::get('/bookings/{booking}', [AdvertiserController::class, 'bookingShow'])->name('booking.show');
        Route::get('/bookings/{booking}', [AdvertiserController::class, 'bookingShow'])
            ->name('booking.show');
        Route::get('/booking-items/{bookingItem}/creative/upload',
            [AdvertiserController::class, 'creativeUpload'])
            ->name('creative.upload');
    });

    // Cart & checkout
    Route::get('/checkout', [CartController::class, 'checkout'])->name('checkout');
    Route::post('/cart/add', [CartController::class, 'add'])->name('cart.add');
    Route::delete('/cart/items/{cartItem}', [CartController::class, 'remove'])->name('cart.remove');
    Route::post('/checkout/pay', [CartController::class, 'pay'])->name('checkout.pay');

    // ============================================================
    // Media owner portal
    // ============================================================
    Route::prefix('owner')->name('owner.')->group(function () {
        Route::get('/dashboard', [OwnerController::class, 'dashboard'])
            ->name('dashboard');
        Route::get('/placements', [OwnerController::class, 'placements'])
            ->name('placements');
        Route::get('/payouts', [OwnerController::class, 'payouts'])
            ->name('payouts');

        // Proof
        Route::get('/proof/{bookingItem}/upload', [ProofController::class, 'create'])
            ->name('proof.upload');
        Route::post('/proof/{bookingItem}/store', [ProofController::class, 'store'])
            ->name('proof.store');
    });

    // ============================================================
    // Admin console
    // ============================================================
    Route::prefix('admin')->name('admin.')->group(function () {
        Route::get('/dashboard',
            [AdminController::class, 'dashboard'])->name('dashboard');
        Route::get('/disputes',
            [AdminController::class, 'disputes'])->name('disputes');
        Route::post('/disputes/{dispute}/resolve',
            [AdminController::class, 'resolveDispute'])->name('disputes.resolve');
        Route::post('/owners/{mediaOwner}/approve',
            [AdminController::class, 'approveOwner'])->name('owners.approve');
        Route::post('/owners/{mediaOwner}/suspend',
            [AdminController::class, 'suspendOwner'])->name('owners.suspend');
        Route::post('/payouts/{payout}/release',
            [AdminController::class, 'releasePayout'])->name('payouts.release');
    });

    // Disputes
    Route::prefix('disputes')->name('disputes.')->group(function () {
        Route::get('/',                    [DisputeController::class, 'index'])
            ->name('index');
        Route::get('/create',              [DisputeController::class, 'create'])
            ->name('create');
        Route::post('/',                   [DisputeController::class, 'store'])
            ->name('store');
        Route::get('/{dispute}',           [DisputeController::class, 'show'])
            ->name('show');
        Route::post('/{dispute}/messages', [DisputeController::class, 'message'])
            ->name('message');
    });

});