<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\DocumentTypeResource;
use App\Models\DocumentType;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;

class DocumentTypeController extends Controller
{
    /**
     * Display the specified resource.
     *
     * @param DocumentTypeIndex $request
     * @return JsonResource|JsonResponse
     */
    public function index()
    {
        $documentTypes = DocumentType::full()
            ->where('status', 'published')
            ->orderBy('title', 'asc')
            ->get();

        if ($documentTypes) {
            return [
                'data' => DocumentTypeResource::collection($documentTypes)
            ];
        }
        return response()->json([], 404);
    }
}
