<?php

namespace App\Modules\HR\Organization\Repositories;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

abstract class OrganizationRepository
{
    /** @return class-string<Model> */
    abstract protected function modelClass(): string;

    public function list(): Collection
    {
        return $this->modelClass()::query()->with($this->relations())->orderBy('name')->get();
    }

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

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

        return $model->fresh();
    }

    /** @return array<int,string> */
    public function listForSelect(): array
    {
        return $this->modelClass()::query()->where('is_active', true)->orderBy('name')->pluck('name', 'id')->all();
    }

    /** @return list<string> */
    protected function relations(): array
    {
        return [];
    }
}
