<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class BookingModel extends Model
{
    protected $table = 'booking';

    protected $primaryKey = 'id_booking';

    protected $keyType = 'string';

    public $incrementing = false;

    protected $fillable = [
        'nama_lengkap',
        'email',
        'no_telp',
        'kode_unik',
        'tgl_booking',
        'deskripsi_tambahan',
        'status_tes',
        'unix_expired_time'
    ];

    protected $casts = [
        'id_booking' => 'string',
    ];

    protected static function boot()
    {
        parent::boot();
        static::creating(function ($model) {
            if (empty($model->id_booking)) {
                $model->id_booking = Str::uuid();
            }

            if(empty($model->status_tes)) {
                $model->status_tes = '1';
            }

            if(empty($model->unix_expired_time)) {
                $model->unix_expired_time = (string) (time() + 86400); // Set expiration time to 24 hour from now
            }
        });
    }
}
