<?php

namespace App\Modules\HR\Contracts\Repositories;

use App\Modules\HR\Contracts\Models\ContractTemplate;
use Illuminate\Database\Eloquent\Collection;

class ContractTemplateRepository
{
    public function list(int $tenantId): Collection
    {
        return ContractTemplate::query()->where('tenant_id', $tenantId)->orderBy('name')->get();
    }

    public function active(int $tenantId): Collection
    {
        return ContractTemplate::query()
            ->where('tenant_id', $tenantId)->where('is_active', true)->orderBy('name')->get();
    }

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

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

        return $template->fresh();
    }
}
