<?php

namespace App\Http\Controllers\Dashboard;
use App\Http\Controllers\Controller;
use App\Http\Requests\Contact\CreateContactRequest;
use App\Http\Requests\Contact\UpdateContactRequest;
use App\Http\Resources\Contact\GetAllContactResource;
use App\Services\ContactService;

class ContactController extends Controller
{
    public function __construct(private ContactService $service)
    {

    }

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

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

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

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