<?php

namespace App\Models\Restaurant;

use Illuminate\Database\Eloquent\Model;
use App\Traits\ChecksTableExistence;

class Order extends Model
{
  //* Support & Extension
    use ChecksTableExistence;
    
  //* Associated Table & Primary Key
    protected $table = 'orders';
    protected $primaryKey = 'id';

  //* Fillable Fields
    protected $fillable = [
        'order_date',
        'order_table',
        'order_cashier',
        'order_payment_method',

        'order_total',
        'order_discount_percentage',
        'order_discount',

        'order_payment',
        'order_change',
    ];

  //* Cast Columns
    protected $casts = [
        'order_date'   => 'datetime',
    ];

  //* Relationships
    // Internal Relations
        public function commands(){
            return $this->hasMany(Comanda::class, 'order_id');
        }

    // Polymorphic Relations
        public function taxInvoice() {
            return $this->morphOne(\App\Models\Invoicing\TaxInvoice::class, 'system_service');
        }
}
