<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Seller\ProductController;
use App\Http\Controllers\Marketplace\StoreController;
use App\Http\Controllers\Seller\OrderController;
use App\Http\Controllers\Seller\SellerDashboardController;

// --- 'seller' MIDDLEWARE ---
Route::prefix('dashboard/seller')->middleware('seller')->group(function () {
    // Seller Dashboard
    Route::get('/', [SellerDashboardController::class, 'index'])->name('dashboard.seller');

    Route::get('/orders', [OrderController::class, 'index'])->name('seller.orders.index');
    Route::put('/orders/{order}', [OrderController::class, 'updateStatus'])->name('seller.orders.update');
    Route::post('/orders/{order}/decline-refund', [OrderController::class, 'declineRefund'])->name('seller.orders.decline-refund');
    
    // Product Management
    Route::get('/products', [ProductController::class, 'index'])->name('seller.products.index');
    Route::get('/products/create', [ProductController::class, 'create'])->name('seller.products.create');
    Route::post('/products', [ProductController::class, 'store'])->name('seller.products.store');
    
    // Product Edit/Update/Delete
    Route::get('/products/{id}/edit', [ProductController::class, 'edit'])->name('seller.products.edit');
    Route::post('/products/{id}', [ProductController::class, 'update'])->name('seller.products.update'); 
    Route::delete('/products/{id}', [ProductController::class, 'destroy'])->name('seller.products.destroy');
    
    Route::post('/products/{id}/feature', [ProductController::class, 'toggleFeatured'])->name('seller.products.toggle-featured');
    
    // Company Profile Routes
    Route::get('/company-profile', [StoreController::class, 'edit'])->name('seller.store-profile.edit');
    Route::put('/company-profile', [StoreController::class, 'update'])->name('seller.store-profile.update');
    
    // --- Handle Store Photo Upload ---
    Route::post('/company-profile/photo', [StoreController::class, 'updatePhoto'])->name('seller.store-profile.photo');

    // --- AI ASSISTANT
    Route::post('/ai-assistant/product-form', [\App\Http\Controllers\AiAssistantController::class, 'processProductForm'])->name('seller.ai.product_form');
});