<?php

namespace App\Models;

use App\Enums\BookingStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Booking extends Model
{
    use HasFactory;

    protected $fillable = [
        'space_id',
        'user_id',
        'billing_details',
        'booking_id',
        'transaction_id',
        'facilities',
        'booking_from',
        'booking_to',
        'stock',
        'gateway_id',
        'total_amount',
    ];

    protected $casts = [
        'billing_details' => 'json',
        'is_paid' => 'boolean',
        'status' => BookingStatus::class,
        'facilities' => 'json',
        'booking_from' => 'datetime',
        'booking_to' => 'datetime',
    ];

    public function space()
    {
        return $this->belongsTo(Space::class, 'space_id');
    }

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

    public function gateway()
    {
        return $this->belongsTo(PaymentMethod::class, 'gateway_id', 'id');
    }

    public function transaction()
    {
        return $this->hasOne(Transaction::class, 'id', 'transaction_id');
    }
}
