<?php

namespace App\Models;

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

    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 = [];

    /**
     * @return mixed
     */

    function getWebProtocolUrlAttribute()
    {
        $webProtocol = 'http://';
        if ($this->is_ssl_active) {
            $webProtocol = 'https://';
        }
        return $webProtocol . $this->domain;
    }

    public function propertyWebTemplate()
    {
        return $this->hasOne('App\Models\PropertyWebTemplate', 'id', 'template_id')->select("id", "name", "folder_name", "status");
    }

    public function propertyWebLanguage()
    {
        return $this->hasOne('App\Models\Language', 'code', 'default_language')->select("code", "name", "language_key");
    }

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

    public function propertyWebMenuMenuMapping()
    {
        return $this->hasMany('App\Models\PropertyWebMenuMapping', 'property_id', 'property_id')
            ->select("id", "property_id", "property_web_id", "property_web_menu_id", "order_number", "status", "type", "menu_code")
            ->orderBy("order_number", "ASC");
    }

    public function propertyWebLanguageMapping()
    {
        return $this->hasMany('App\Models\PropertyWebLanguageMapping', 'property_id', 'property_id')
            ->select("id", "property_id", "property_web_id", "language_code", "status");
    }

    public function propertyGroupMapping()
    {
        return $this->hasMany('App\Models\PropertyGroupMapping', 'property_id', 'property_id')
            ->select("id", "property_id", "property_group_id", "order_number", "status")
            ->where('status', 1);
    }

    public function propertyWebPhotoMapping()
    {
        return $this->hasMany('App\Models\PropertyWebPhotoMapping', 'property_web_id', 'id')
            ->where('status', '=', 1);
    }

    public function property()
    {
        return $this->hasOne('App\Models\Property', 'id', 'property_id')
            ->select('id', 'country', 'name', 'property_type_id', 'chain_id', 'official_name',
                'tax_office', 'tax_number', 'currency_type', 'country', 'content_code', 'status');
    }

    public function propertyWebAbout()
    {
        return $this->hasMany('App\Models\PropertyWebAboutUs', 'property_id', 'property_id')->select('id', 'property_id', 'language_code', 'value');
    }

    public function propertyWebPopup()
    {
        return $this->hasMany('App\Models\PropertyWebPopup', 'property_id', 'property_id')
            ->select('id', 'property_id', 'language_code', 'code', 'title', 'start_date', 'url', 'end_date', 'image')->where('status', 1);
    }

    public function propertyWebWeather()
    {
        return $this->hasOne('App\Models\PropertyWebWeather', 'property_id', 'property_id')->select('id', 'property_id', 'date', 'location', 'temp', 'conditions', 'icon');
    }


    public function propertyWebComponent()
    {
        return $this->hasMany('App\Models\PropertyWebComponentMapping', 'property_id', 'property_id')
            ->select('id', 'property_id', 'channel_id', 'component_id', 'parameter', 'language', 'status')->where('status', 1);
    }

    public function propertyWebRoomMapping()
    {
        return $this->hasMany('App\Models\PropertyWebRoomMapping', 'property_web_id', 'id')
            ->select("id", "property_id", "property_web_id", "property_room_id", "status")
            ->where('status', 1);
    }

    public function propertyWebPlaceMapping()
    {
        return $this->hasMany('App\Models\PropertyWebPlaceMapping', 'property_web_id', 'id')
            ->select("id", "property_id", "property_web_id", "property_place_id", "status")
            ->where('status', 1);
    }

    public function propertyWebColorMapping()
    {
        return $this->hasMany('App\Models\PropertyWebColorMapping', 'property_web_id', 'id')
            ->select('id', 'property_id', 'property_web_id', 'color_code', 'order_number')
            ->where('status', 1)
            ->orderBy('order_number');
    }

    public function propertyWebContent()
    {
        return $this->hasMany('App\Models\PropertyWebContent', 'property_id', 'property_id')
            ->select('id', 'property_id', 'content_category_id', 'title', 'slug', 'language_code', 'content', 'image', 'status')->where('status', 1);
    }

    public function propertyWebContentSummary()
    {
        return $this->hasMany('App\Models\PropertyWebContent', 'property_id', 'property_id')
            ->select('id', 'property_id', 'content_category_id', 'title', 'slug', 'language_code', 'image', 'status')->where('status', 1);
    }

    public function propertyWebMetaMapping()
    {
        return $this->hasMany('App\Models\PropertyWebMetaMapping', 'property_web_id', 'id')
            ->where('status', 1);
    }

}
