<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\PropertyController;
use App\Http\Controllers\AboutController;
use App\Http\Controllers\AgentController;
use App\Http\Controllers\BlogController;
use App\Http\Controllers\CalculatorController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\AgentPortalController;
use App\Http\Controllers\NeighborhoodController;
use App\Http\Controllers\ValuationController;
use App\Http\Controllers\GalleryController;

// Public Routes
Route::get('/', [HomeController::class, 'index'])->name('home');
Route::post('/subscribe', [HomeController::class, 'subscribeNewsletter'])->name('newsletter.subscribe');

Route::get('/properties', [PropertyController::class, 'index'])->name('properties.index');
Route::get('/properties/{slug}', [PropertyController::class, 'show'])->name('properties.show');
Route::post('/properties/{id}/inquire', [PropertyController::class, 'submitInquiry'])->name('properties.inquire');
Route::post('/properties/{id}/book-viewing', [PropertyController::class, 'bookViewing'])->name('properties.book-viewing');

Route::get('/neighborhoods', [NeighborhoodController::class, 'index'])->name('neighborhoods.index');
Route::get('/neighborhoods/{slug}', [NeighborhoodController::class, 'show'])->name('neighborhoods.show');

Route::get('/valuation', [ValuationController::class, 'index'])->name('valuation');
Route::post('/valuation', [ValuationController::class, 'store'])->name('valuation.store');

Route::get('/gallery', [GalleryController::class, 'index'])->name('gallery.index');

Route::get('/about', [AboutController::class, 'index'])->name('about');

Route::get('/agents', [AgentController::class, 'index'])->name('agents.index');
Route::get('/agents/{id}', [AgentController::class, 'show'])->name('agents.show');

Route::get('/blog', [BlogController::class, 'index'])->name('blog.index');
Route::get('/blog/{slug}', [BlogController::class, 'show'])->name('blog.show');

Route::get('/lands', [PropertyController::class, 'lands'])->name('lands.index');

Route::get('/calculator', [CalculatorController::class, 'index'])->name('calculator');

Route::get('/contact', [ContactController::class, 'index'])->name('contact');
Route::post('/contact', [ContactController::class, 'store'])->name('contact.store');

// Auth Routes (Agent & Admin Login)
Route::get('/login', [AgentPortalController::class, 'showLoginForm'])->name('login');
Route::post('/login', [AgentPortalController::class, 'login']);
Route::post('/logout', [AgentPortalController::class, 'logout'])->name('logout');

// Agent Portal Routes (For Logged-in Agents)
Route::prefix('agent')->name('agent.')->middleware('auth')->group(function () {
    Route::get('/dashboard', [AgentPortalController::class, 'dashboard'])->name('dashboard');
    Route::get('/properties/create', [AgentPortalController::class, 'createProperty'])->name('properties.create');
    Route::post('/properties/store', [AgentPortalController::class, 'storeProperty'])->name('properties.store');
    Route::get('/profile', [AgentPortalController::class, 'editProfile'])->name('profile');
    Route::post('/profile', [AgentPortalController::class, 'updateProfile'])->name('profile.update');
});

// Admin Panel Routes (Complete Site Management)
Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('/', [AdminController::class, 'dashboard'])->name('dashboard');
    
    // Major Homepage Promotions Management
    Route::get('/promotions', [AdminController::class, 'promotions'])->name('promotions');
    Route::get('/promotions/create', [AdminController::class, 'createPromotion'])->name('promotions.create');
    Route::post('/promotions/store', [AdminController::class, 'storePromotion'])->name('promotions.store');
    Route::delete('/promotions/{id}', [AdminController::class, 'deletePromotion'])->name('promotions.delete');

    // Properties
    Route::get('/properties', [AdminController::class, 'properties'])->name('properties');
    Route::get('/properties/create', [AdminController::class, 'createProperty'])->name('properties.create');
    Route::post('/properties/store', [AdminController::class, 'storeProperty'])->name('properties.store');
    Route::get('/properties/{id}/edit', [AdminController::class, 'editProperty'])->name('properties.edit');
    Route::post('/properties/{id}/update', [AdminController::class, 'updateProperty'])->name('properties.update');
    Route::delete('/properties/{id}', [AdminController::class, 'deleteProperty'])->name('properties.delete');
    
    // Agents Management
    Route::get('/agents', [AdminController::class, 'agents'])->name('agents');
    Route::get('/agents/create', [AdminController::class, 'createAgent'])->name('agents.create');
    Route::post('/agents/store', [AdminController::class, 'storeAgent'])->name('agents.store');
    Route::delete('/agents/{id}', [AdminController::class, 'deleteAgent'])->name('agents.delete');

    // Blog Posts Management
    Route::get('/blog', [AdminController::class, 'blog'])->name('blog');
    Route::get('/blog/create', [AdminController::class, 'createBlogPost'])->name('blog.create');
    Route::post('/blog/store', [AdminController::class, 'storeBlogPost'])->name('blog.store');
    Route::delete('/blog/{id}', [AdminController::class, 'deleteBlogPost'])->name('blog.delete');

    // Photo Gallery & Site Inspection Media Manager
    Route::get('/gallery', [AdminController::class, 'gallery'])->name('gallery');
    Route::get('/gallery/create', [AdminController::class, 'createGallery'])->name('gallery.create');
    Route::post('/gallery/store', [AdminController::class, 'storeGallery'])->name('gallery.store');
    Route::delete('/gallery/{id}', [AdminController::class, 'deleteGallery'])->name('gallery.delete');

    // Inquiries & Appointments
    Route::get('/inquiries', [AdminController::class, 'inquiries'])->name('inquiries');
    Route::post('/inquiries/{id}/status', [AdminController::class, 'updateInquiryStatus'])->name('inquiries.status');
    
    Route::get('/appointments', [AdminController::class, 'appointments'])->name('appointments');
    Route::post('/appointments/{id}/status', [AdminController::class, 'updateAppointmentStatus'])->name('appointments.status');
    
    // Subscribers
    Route::get('/subscribers', [AdminController::class, 'subscribers'])->name('subscribers');
    Route::delete('/subscribers/{id}', [AdminController::class, 'deleteSubscriber'])->name('subscribers.delete');

    // Site Settings
    Route::get('/settings', [AdminController::class, 'settings'])->name('settings');
    Route::post('/settings', [AdminController::class, 'updateSettings'])->name('settings.update');
});
