<?php

declare(strict_types=1);

namespace App\Repositories;

use App\Contracts\Repositories\AmenityRepositoryInterface;
use App\Models\Amenity;
use Illuminate\Database\Eloquent\Collection;

final class EloquentAmenityRepository implements AmenityRepositoryInterface
{
    public function getAll(): Collection
    {
        return Amenity::orderBy('category')->orderBy('name')->get();
    }

    public function getByCategory(string $category): Collection
    {
        return Amenity::byCategory($category)->orderBy('name')->get();
    }

    public function getEssentials(): Collection
    {
        return Amenity::essentials()->orderBy('name')->get();
    }

    public function getFeatures(): Collection
    {
        return Amenity::features()->orderBy('name')->get();
    }

    public function getSafety(): Collection
    {
        return Amenity::safety()->orderBy('name')->get();
    }

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

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

    public function update(int $id, array $data): Amenity
    {
        $amenity = Amenity::findOrFail($id);
        $amenity->update($data);

        return $amenity->fresh();
    }

    public function delete(int $id): bool
    {
        $amenity = Amenity::findOrFail($id);

        return $amenity->delete();
    }
}
