<?php

namespace App\Models;

class BookingContact extends BaseModel
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'booking_contact';
    protected $appends = ['nameSurname','phoneFormatted','invoiceArray'];

    const CREATED_AT = 'created_at';
    const UPDATED_AT = 'updated_at';

    protected $dateFormat = 'U';
    protected $guarded = [];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [];

    public function getNameSurnameAttribute()
    {
        return $this->name . ' ' . $this->surname;
    }

    public function getPhoneFormattedAttribute()
    {
        return $this->phone_code . '' . $this->phone_number;
    }

    public function getInvoiceArrayAttribute()
    {
        if (!is_null($this->invoice)) {
            return json_decode($this->invoice, 1);
        } else {
            return null;
        }
    }
}
