<?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Http\Requests\Works\CreateWorksRequest;
use App\Http\Requests\Works\UpdateWorksRequest;
use App\Http\Resources\Works\WorksResource;
use App\Services\WorksService;

class WorksController extends Controller
{
    public function __construct(private WorksService $service)
    {

    }

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

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

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

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