<?php

namespace App\Http\Controllers\Public;

use App\Http\Controllers\Controller;
use App\Models\Vehicle;
use App\Models\AuctionVehicle;
use App\Models\BlogPost;
use App\Models\Faq;
use App\Models\SeoMeta;
use App\Services\SEO\SchemaGenerator;

class HomeController extends Controller
{
    public function index()
    {
        $featuredStock = Vehicle::available()->featured()->take(6)->get();
        $latestArrivals = Vehicle::available()->newArrival()->take(8)->get();
        $liveAuctions = AuctionVehicle::with('auctionHouse')->active()->orderBy('auction_ends_at', 'asc')->take(6)->get();
        $recentBlogs = BlogPost::published()->take(3)->get();
        $faqs = Faq::where('is_active', true)->orderBy('sort_order', 'asc')->take(6)->get();

        $seo = SeoMeta::where('url_path', '/')->first();
        $schemaJson = SchemaGenerator::organization();

        // Get filter dropdown options
        $makes = Vehicle::distinct()->pluck('make')->filter();
        $bodyTypes = Vehicle::distinct()->pluck('body_type')->filter();
        $years = Vehicle::distinct()->orderBy('year', 'desc')->pluck('year')->filter();

        return view('public.home', compact(
            'featuredStock',
            'latestArrivals',
            'liveAuctions',
            'recentBlogs',
            'faqs',
            'seo',
            'schemaJson',
            'makes',
            'bodyTypes',
            'years'
        ));
    }
}
