<?php

namespace App\Http\Controllers\Dashboard;
use App\Http\Controllers\Controller;
use App\Http\Requests\Projects\CreateProjectsRequest;
use App\Http\Requests\Projects\UpdateProjectsRequest;
use App\Http\Resources\Projects\ProjectsResource;
use App\Http\Resources\Projects\SingleProjectsResource;
use App\Services\ProjectsService;

class ProjectsController extends Controller
{
    public function __construct(private ProjectsService $service)
    {

    }    
    public function getOne($id) 
    {
        $data = $this->service->getOne($id);
        $response = new  SingleProjectsResource($data);
        return response()->json($response);
    }
    public function getAll() 
    {
        $data = $this->service->getAll();
        $response = ProjectsResource::collection($data);
        return response()->json($response);
    }

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

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

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