<?php

namespace App\Http\Controllers\Dashboard;
use App\Http\Controllers\Controller;
use App\Http\Requests\RecentWorks\CreateRecentWorksRequest;
use App\Http\Requests\RecentWorks\UpdateRecentWorksRequest;
use App\Http\Resources\Recent\RecentWorksResource;
use App\Services\RecentWorksService;

class RecentWorksController extends Controller
{
    public function __construct(private RecentWorksService $service)
    {

    }

    public function getAll()
    {
        $data = $this->service->getAll();
        $response = RecentWorksResource::collection($data);
        return response()->json($response);
    }

    public function create(CreateRecentWorksRequest $request)
    {
        $data = $this->service->create($request->validated());
        return response()->json($data);
    }

    public function update(UpdateRecentWorksRequest $request)
    {
        $data = $this->service->updateRecentWorks($request->id, $request->validated());
        return response()->json($data);
    }

    public function delete($id)
    {
        $data = $this->service->delete($id);
        return response()->json($data);
    }
}