<?php

namespace App\Modules\HR\Organization\Services;

use App\Modules\HR\Organization\DTOs\OrganizationWriteData;
use App\Modules\HR\Organization\Repositories\OrganizationRepository;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

abstract class OrganizationService
{
    public function __construct(protected readonly OrganizationRepository $repository) {}

    public function list(): Collection
    {
        return $this->repository->list();
    }

    public function store(OrganizationWriteData $data): Model
    {
        return $this->repository->create(array_merge($data->toArray(), ['tenant_id' => (int) auth()->user()->tenant_id]));
    }

    public function update(Model $model, OrganizationWriteData $data): Model
    {
        return $this->repository->update($model, $data->toArray());
    }

    public function deactivate(Model $model): void
    {
        $this->repository->update($model, ['is_active' => false]);
    }
}
