<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Announcement;
use Illuminate\Support\Facades\Log;

class AnnouncementController extends Controller
{
    public function latest()
    {
        try {
            $announcement = Announcement::latest()->first();
            
            // Debug log
            Log::info('Latest announcement:', ['data' => $announcement]);
            
            if (!$announcement) {
                return response()->json([
                    'success' => false,
                    'message' => 'No announcement found',
                    'data' => null
                ]);
            }

            return response()->json([
                'success' => true,
                'data' => $announcement
            ]);
            
        } catch (\Exception $e) {
            Log::error('Error fetching announcement: ' . $e->getMessage());
            
            return response()->json([
                'success' => false,
                'message' => 'Error fetching announcement',
                'error' => $e->getMessage()
            ], 500);
        }
    }
} 