<?php

namespace App\Services;

use App\Models\ServiceType;
use Illuminate\Database\Eloquent\Collection;

class ServiceTypeService
{
    public function getAll(): Collection
    {
        return ServiceType::query()
            ->orderBy('created_at', 'desc')
            ->get();
    }

    public function findById(int $id): ?ServiceType
    {
        return ServiceType::find($id);
    }

    public function create(array $data): ServiceType
    {
        return ServiceType::create($data);
    }

    public function update(int $id, array $data): ?ServiceType
    {
        $model = $this->findById($id);

        if (! $model) {
            return null;
        }

        $model->update($data);

        return $model->fresh();
    }

    public function delete(int $id): bool
    {
        $model = $this->findById($id);

        if (! $model) {
            return false;
        }

        return $model->delete();
    }

    // Add custom business logic methods here
}
