<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use App\Models\Photo;

class PhotoController extends Controller
{
    public function index(): JsonResponse
    {
        $photos = Photo::orderBy('sort_order', 'asc')->get();

        $photosWithPaths = $photos->map(function ($photo) {
            $data = $photo->toArray();
            $data['photo'] = $photo->photo ? '/storage/' . $photo->photo : null;
            return $data;
        });

        return response()->json([
            'status' => 'success',
            'data' => $photosWithPaths
        ]);
    }
}
