<?php

namespace App\Models\Hotel;

use Illuminate\Database\Eloquent\Model;

class Reservation extends Model
{
  //* Associated Table & Primary Key
    protected $table = 'reservations';
    protected $primaryKey = 'id';

  //* Fillable Fields
    protected $fillable = [
        //* Basic Data

        // Of Creation
        'reservation_date',
        'receptionist_id',
        'checkin_receptionist_id',

        // Of Registration
        'client_id',
        'client_reference',
        'date_entry',
        'hour_entry',
        'date_departure',
        'hour_departure',
        'number_nights',
        'number_hours',
        'number_adults',
        'number_children',
        'include_children_in_pax',
        'requiere_invoice',
        'invoice_uuid',
        'reservation_reason',
        'notes',

        // Of Stay
        'is_express',
        'room_id',
        'roomType_id',
        'regimen_id',

        // Of Contact
        'agency_id',
        'source_id',

        // Of Payment
        'discount_percentage',
        'original_suggested_price',
        'suggested_price',
        'final_price',
        'total_price',
        'lodging_contract',
        'consumption_contract',
        'extras_contract',

        //* Control Data
        'status_id',
        'guest_status_id',
        'has_checkIn',
        'has_checkOut',
        'payment_status',
        'show_in_calendar',
    ];

  //* Cast Columns
    protected $casts = [
        'requiere_invoice' => 'boolean',
        'include_children_in_pax' => 'boolean',
        'is_express' => 'boolean',
    ];

  //* Relationships
    // Of Creation
        public function user() {
            return $this->belongsTo(\App\Models\User::class, 'receptionist_id');
        }
        public function checkinUser() {
            return $this->belongsTo(\App\Models\User::class, 'checkin_receptionist_id');
        }

    // Of Registration
        public function client() {
            return $this->belongsTo(Client::class);
        }

    // Of Stay
        public function room() {
            return $this->belongsTo(Room::class, 'room_id');
        }

        public function roomType() {
            return $this->belongsTo(RoomType::class, 'roomType_id');
        }

        public function regimen() {
            return $this->belongsTo(Regimen::class);
        }

    // Of Contact
        public function agency() {
            return $this->belongsTo(Agency::class, 'agency_id');
        }

        public function source() {
            return $this->belongsTo(Source::class)->withDefault();
        }

    // Control Data
        public function status() {
            return $this->belongsTo(Status::class, 'status_id');
        }

        public function guestStatus() {
            return $this->belongsTo(Status::class, 'guest_status_id');
        }

    // Payments And Charges
        public function lodgingPayments() {
            return $this->hasMany(LodgingPayments::class);
        }

        public function extraPayments() {
            return $this->hasMany(ExtraPayments::class);
        }

        public function consumptionPayments() {
            return $this->hasMany(ConsumptionPayments::class);
        }

        public function extraCharges() {
            return $this->hasMany(ExtraCharges::class);
        }

        public function consumptionCharges() {
            return $this->hasMany(ConsumptionCharges::class);
        }

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