<?php

namespace App\Modules\HR\Employees\Repositories;

use App\Modules\HR\Employees\Models\EmployeeSkill;
use Illuminate\Support\Collection;

class EmployeeSkillRepository
{
    public function listForEmployee(int $tenantId, int $employeeId): Collection
    {
        return EmployeeSkill::query()
            ->where('tenant_id', $tenantId)
            ->where('employee_id', $employeeId)
            ->orderBy('name')
            ->get();
    }

    public function findForEmployee(int $tenantId, int $employeeId, int $id): ?EmployeeSkill
    {
        return EmployeeSkill::query()
            ->where('tenant_id', $tenantId)
            ->where('employee_id', $employeeId)
            ->whereKey($id)
            ->first();
    }

    /** @param  array<string, mixed>  $data */
    public function create(array $data): EmployeeSkill
    {
        return EmployeeSkill::query()->create($data);
    }

    /** @param  array<string, mixed>  $data */
    public function update(EmployeeSkill $skill, array $data): EmployeeSkill
    {
        $skill->update($data);

        return $skill->fresh();
    }

    public function delete(EmployeeSkill $skill): void
    {
        $skill->delete();
    }
}
