<?php

namespace App\Models;

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

/**
 * @mixin IdeHelperListingMedia
 */
class ListingMedia extends Model
{
    use HasFactory;

    protected $table = 'listing_media';

    protected $fillable = [
        'listing_id',
        'file_path',
        'file_url',
        'alt_text',
        'mime_type',
        'size',
        'sort_order',
        'is_cover',
    ];

    protected $casts = [
        'size' => 'integer',
        'sort_order' => 'integer',
        'is_cover' => 'boolean',
    ];

    public function listing()
    {
        return $this->belongsTo(Listing::class);
    }

    public function scopeCover($query)
    {
        return $query->where('is_cover', true);
    }
}