<?php

namespace App\Http\Controllers;

use App\Enums\StatutAnnonce;
use App\Models\Annonce;
use App\Models\Article;

class SitemapController extends Controller
{
    public function index()
    {
        $annonces = Annonce::query()
            ->where('statut', StatutAnnonce::Publiee)
            ->select('id', 'updated_at')
            ->latest('updated_at')
            ->get();

        $articles = Article::query()
            ->where('publie', true)
            ->select('slug', 'updated_at')
            ->latest('updated_at')
            ->get();

        return response()
            ->view('sitemap', compact('annonces', 'articles'))
            ->header('Content-Type', 'text/xml');
    }
}