<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Bookings extends Model
{
    public $table = 'bookings';

    public $fillable = [
        'name',
        'customer_id',
        'phone',
        'email',
        'seat_id',
        'seat_name',
        'branch_id',
        'company_id',
        'subtotal',
        'amount',
        'discount',
        'status',
        'coupon_discount',
        'coupon_id',
        'booking_date',
        'booking_time',
        'created_by',
        'assigned_to',
        'booking_from',
        'change',
        'print',
        'note',
        'status_by',
        'reason',
        'payment'
    ];

    protected $casts = [
        'name' => 'string',
        'phone' => 'string',
        'email' => 'string',
        'seat_name' => 'string',
        'subtotal' => 'decimal:2',
        'amount' => 'decimal:2',
        'discount' => 'decimal:2',
        'status' => 'integer',
        'change' => 'decimal:2',
        'print' => 'integer',
        'payment' => 'integer'
    ];

    public static array $rules = [
        'name' => 'nullable|string|max:255',
        'phone' => 'nullable|string|max:255',
        'email' => 'nullable|string|max:255',
        'seat_id' => 'nullable',
        'seat_name' => 'nullable|string|max:255',
        'branch_id' => 'nullable',
        'company_id' => 'nullable',
        'subtotal' => 'nullable|numeric',
        'amount' => 'nullable|numeric',
        'discount' => 'nullable|numeric',
        'status' => 'nullable|numeric',
        'coupon_id' => 'nullable',
        'booking_time' => 'nullable',
        'created_by' => 'nullable',
        'created_at' => 'nullable',
        'updated_at' => 'nullable',
        'change' => 'nullable|numeric',
        'print' => 'nullable|numeric',
        'payment' => 'nullable|numeric'
    ];
    public function items(){
        return $this->hasMany(BookingItems::class,'booking_id','id');
      }
      public function payments(){
        return $this->hasMany(BookingPayments::class,'booking_id','id');
      }
      public function branch(){
        return $this->hasOne(Branches::class,'id','branch_id');
      }
      public function customer(){
        return $this->hasOne(Customers::class,'id','customer_id');
      }
      public function seat(){
        return $this->hasOne(Seats::class,'id','seat_id');
      }
      public function staff(){
        return $this->hasOne(User::class,'id','assigned_to');
      }
}
