<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Listing extends BaseModel
{
    use SoftDeletes;

    protected $hidden = ['location'];

    protected function casts(): array
    {
        return [
            'latitude' => 'decimal:8', 'longitude' => 'decimal:8',
            'base_price_usd' => 'decimal:2', 'base_price_eur' => 'decimal:2',
            'base_price_gbp' => 'decimal:2', 'base_price_ngn' => 'decimal:2',
            'cleaning_fee' => 'decimal:2', 'service_fee' => 'decimal:2',
            'average_rating' => 'decimal:2', 'is_new' => 'boolean',
            'is_featured' => 'boolean', 'published_at' => 'datetime',
        ];
    }

    public function partner(): BelongsTo { return $this->belongsTo(Partner::class); }
    public function images(): HasMany { return $this->hasMany(ListingImage::class)->orderBy('order'); }
    public function listingAmenities(): HasMany { return $this->hasMany(ListingAmenity::class); }
    public function amenities(): BelongsToMany { return $this->belongsToMany(Amenity::class, 'listing_amenities'); }
    public function availability(): HasMany { return $this->hasMany(Availability::class); }
    public function bookings(): HasMany { return $this->hasMany(Booking::class); }
    public function reviews(): HasMany { return $this->hasMany(Review::class); }
    public function favorites(): HasMany { return $this->hasMany(Favorite::class); }
}