<?php

namespace App\Repositories;

use App\Models\Pegawai;

class PegawaiRepository
{

    protected $pegawai;

    public function __construct(Pegawai $pegawai)
    {
        $this->pegawai = $pegawai;
    }

    public function getAll()
    {
        return $this->pegawai->all();
    }

    public function findById(int $id)
    {
        return $this->pegawai->find($id);
    }

    public function createPegawai(array $data): Pegawai
    {
        return $this->pegawai->create($data);
    }

    public function updatePegawai(int $id, array $data): ?Pegawai
    {
        $pegawai = $this->findById($id);
        $pegawai->update($data);
        return $pegawai;
    }

    public function deletePegawai($id)
    {
        $pegawai = $this->findById($id);
        return $pegawai->delete();
    }
}
