<?php

namespace App\Models;

class Booking extends BaseModel
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'booking';
    protected $appends = [];

    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 bookingContact()
    {
        return $this->hasOne('App\Models\BookingContact', 'booking_id', 'id')
            ->select(['id', 'booking_id', 'name', 'surname', 'phone_code', 'phone_number', 'email', 'note', 'extra_param', 'language_code', 'country_code', 'invoice_request', 'invoice']);
    }

    public function bookingChannel()
    {
        return $this->hasOne('App\Models\PropertyChannel', 'id', 'channel_id')
            ->select(['id', 'name', 'official_name', 'channel_category_id', 'description', 'country_code', 'default_currency', 'logo']);
    }

    public function channelManager()
    {
        return $this->hasOne('App\Models\ChannelManager', 'id', 'channel_manager_id')
            ->select(['id', 'name', 'status']);
    }

    public function bookingPaymentType()
    {
        return $this->hasOne('App\Models\PropertyBookingPaymentType', 'code', 'payment_type_code')
            ->select(['name', 'language_key', 'code']);
    }

    public function bookingRoom()
    {
        return $this->hasMany('App\Models\BookingRoom', 'booking_id', 'id')
            ->select(['id', 'booking_id', 'occupancy_code', 'checkin_date', 'checkout_date', 'availability_code', 'room_id', 'room_name',
                'room_rate_name', 'room_rate_mapping_id', 'cancellation_policy', 'rate_detail', 'extra_param', 'daily_amount', 'amount', 'discount_amount',
                'total', 'currency_code', 'property_room_bed_id', 'property_room_bed_group_id', 'smoking_fact_id', 'status']);
    }

    public function bookingRoomSummary()
    {
        return $this->hasMany('App\Models\BookingRoom', 'booking_id', 'id')
            ->select(['id', 'booking_id', 'occupancy_code', 'checkin_date', 'checkout_date', 'room_id', 'room_name', 'room_rate_name', 'total', 'currency_code', 'status']);
    }

    public function bookingRoomPax()
    {
        return $this->hasMany('App\Models\BookingRoomPax', 'booking_id', 'id')
            ->select(['id', 'booking_id', 'booking_room_id', 'type', 'name', 'surname', 'gender', 'citizen', 'birth_date', 'status']);
    }

    public function bookingAddon()
    {
        return $this->hasMany('App\Models\BookingAddon', 'booking_id', 'id')
            ->select(['id', 'booking_id', 'property_channel_addon_id', 'count', 'amount', 'total', 'currency_code', 'attribute']);
    }

    public function bookingPayment()
    {
        return $this->hasOne('App\Models\BookingPayment', 'booking_id', 'id')->orderByDesc('id');
    }

    public function bookingPaymentData()
    {
        return $this->hasMany('App\Models\BookingPaymentData', 'booking_id', 'id')->orderByDesc('id')
            ->select(['id', 'booking_id', 'type', 'data']);
    }

    public function bookingPaymentDataCheck()
    {
        return $this->hasMany('App\Models\BookingPaymentDataCheck', 'booking_id', 'id')->orderBy('id');
    }

    public function bookingProperty()
    {
        return $this->hasOne('App\Models\Property', 'id', 'property_id')
            ->select(['id', 'name', 'country', 'official_name', 'tax_office', 'tax_number', 'commission', 'commission_offline', 'commission_channel', 'commission_wholesaler']);
    }

    public function propertyBookingEngine()
    {
        return $this->hasOne('App\Models\PropertyBookingEngine', 'property_id', 'property_id')
            ->select(['id', 'property_id', 'channel_id', 'token'])
            ->where('channel_id', '=', 1);
    }

    public function propertyBookingChannel()
    {
        return $this->hasOne('App\Models\PropertyChannel', 'id', 'channel_id')
            ->select(["id", "parent_id", "name", "official_name", "token", "description", "channel_category_id", "country_code", "currency_code", "default_currency", "logo", "address", "zip_code", "email", "phone", "phone2", "fax", "score"]);
    }

    public function bookingPropertyWeb()
    {
        return $this->hasOne('App\Models\PropertyWeb', 'property_id', 'property_id');
    }

    public function bookingPaymentTransaction()
    {
        return $this->hasMany('App\Models\PaymentTransaction', 'order_id', 'booking_code')
            ->orderByDesc('id');
    }

    public function bookingStatus()
    {
        return $this->hasOne('App\Models\BookingStatus', 'id', 'status')
            ->select(['name', 'language_key', 'id'])->where('status', 1);
    }

    public function property()
    {
        return $this->hasOne("App\Models\Property", 'id', 'property_id')->select(['id', 'name']);
    }

    public function bookingActiveMessageCount()
    {
        return $this->hasMany('App\Models\BookingTicket', 'booking_id', 'id')
            ->select(['id', 'booking_id', 'code', 'parent_id'])
            ->where('status', 1)->where('user_id', null)->where('is_viewed', null)
            ->where('is_log', null);
    }

    public function propertyChannelMapping()
    {
        return $this->hasOne('App\Models\PropertyChannelMapping', 'property_id', 'property_id')
            ->where('channel_id', '=', 1)
            ->select("id", "property_id", "channel_id", "currency_code", "channel_tax_id", "status");
    }


    public function propertyBookingEngineSearch()
    {
        return $this->hasOne('App\Models\PropertyBookingEngineSearch', 'search_key', 'search_key')
            ->where('channel_id', '=', 1)->select();
    }

    public function channelManagerBooking()
    {
        return $this->hasMany('App\Models\ChannelManagerBooking', 'booking_id', 'id')
            ->select(['id', 'property_id', 'booking_id','channel_manager_id', 'type', 'is_pushed', 'status']);
    }
}
