<?php

namespace App\Services;

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

class StateService
{
    public function getAll(): Collection
    {
        return State::query()->orderBy('name', 'asc')->get();
    }

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

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

    public function update(int $id, array $data): ?State
    {
        $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
}
