<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\CreatePegawaiRequest;
use App\Http\Requests\UpdatePegawaiRequest;
use App\Services\PegawaiService;

class PegawaiController extends Controller
{
    protected $pegawaiService;

    public function __construct(PegawaiService $pegawaiService)
    {
        $this->pegawaiService = $pegawaiService;
    }

    public function index()
    {
        return $this->pegawaiService->getAllPegawai();
    }

    public function create() {}

    public function store(CreatePegawaiRequest $request)
    {
        $validatedData = $request->validated();
        return $this->pegawaiService->createPegawai($validatedData);
    }

    public function show(string $id)
    {
        return $this->pegawaiService->findById($id);
    }

    public function edit(string $id)
    {
        //
    }

    public function update(UpdatePegawaiRequest $request, string $id)
    {
        $validatedData = $request->validated();
        return $this->pegawaiService->updatePegawai($id, $validatedData);
    }

    public function destroy(string $id)
    {
        return $this->pegawaiService->deletePegawai($id);
    }
}
