<?php

namespace App\Models;

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

class TimeSlot extends Model
{
    use HasFactory;

    protected $fillable = [
        'lapangan_id', 'jam_mulai', 'jam_selesai',
        'is_available', 'harga',
    ];

    protected $casts = [
        'is_available' => 'boolean',
        'harga'        => 'integer',
    ];

    public function lapangan()
    {
        return $this->belongsTo(Lapangan::class);
    }

    /** Harga efektif: pakai harga slot jika ada, atau harga lapangan */
    public function getHargaEfektifAttribute(): int
    {
        return $this->harga ?? ($this->lapangan->harga_per_jam ?? 0);
    }
}
