<?php

use App\Http\Controllers\ProfileController;
use App\Http\Controllers\ProductController; // Added
use App\Http\Controllers\ProductDescriptionController; // Added
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    // Redirect root to extractor if logged in, else login
    return auth()->check() ? redirect()->route('extractor') : redirect()->route('login');
});

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

Route::middleware('auth')->group(function () {
    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');

    // Product Extractor
    Route::get('/extractor', [ProductController::class, 'index'])->name('extractor');
    Route::post('/upload', [ProductController::class, 'upload'])->name('upload');
    Route::post('/approve', [ProductController::class, 'approve'])->name('approve');
    Route::get('/attributes/{id}/terms', [ProductController::class, 'getAttributeTerms'])->name('attributes.terms');

    // Description Generator
    Route::get('/description-generator', [ProductDescriptionController::class, 'index'])->name('description.generator');
    Route::post('/generate-description', [ProductDescriptionController::class, 'generate'])->name('description.generate');

    // Pick List
    Route::get('/picklist', [App\Http\Controllers\PickListController::class, 'index'])->name('picklist');
    Route::post('/picklist/generate', [App\Http\Controllers\PickListController::class, 'generate'])->name('picklist.generate');
});

require __DIR__.'/auth.php';
