<?php

namespace App\Models;

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

class Lapangan extends Model
{
    use HasFactory;

    protected $table = 'lapangan';

    protected $fillable = [
        'nama', 'deskripsi', 'jenis_olahraga',
        'harga_per_jam', 'lokasi', 'alamat',
        'foto', 'fasilitas', 'jam_buka', 'jam_tutup',
        'is_active', 'rating', 'total_review', 'owner_id',
    ];

    protected $casts = [
        'foto'          => 'array',
        'fasilitas'     => 'array',
        'is_active'     => 'boolean',
        'harga_per_jam' => 'integer',
        'rating'        => 'float',
        'total_review'  => 'integer',
    ];

    public function owner()
    {
        return $this->belongsTo(User::class, 'owner_id');
    }

    public function bookings()
    {
        return $this->hasMany(Booking::class);
    }

    public function timeSlots()
    {
        return $this->hasMany(TimeSlot::class);
    }

    /** Scope: hanya lapangan yang aktif */
    public function scopeAktif($query)
    {
        return $query->where('is_active', true);
    }
}
