<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

final class Amenity extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'icon',
        'category',
    ];

    protected function casts(): array
    {
        return [
            'created_at' => 'datetime',
            'updated_at' => 'datetime',
        ];
    }

    public function properties(): BelongsToMany
    {
        return $this->belongsToMany(Property::class)->withTimestamps();
    }

    /**
     * Scope to get amenities by category
     */
    public function scopeByCategory($query, string $category)
    {
        return $query->where('category', $category);
    }

    /**
     * Scope to get essentials
     */
    public function scopeEssentials($query)
    {
        return $query->where('category', 'essentials');
    }

    /**
     * Scope to get features
     */
    public function scopeFeatures($query)
    {
        return $query->where('category', 'features');
    }

    /**
     * Scope to get safety amenities
     */
    public function scopeSafety($query)
    {
        return $query->where('category', 'safety');
    }
}
