<?php

namespace App\Models;

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

    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
     */



    public function getRoomSizeTypeFormattedAttribute()
    {
        $roomSizeTypes = [
            'mt' => 'm²',
            'ft' => 'ft² sq'
        ];

        $roomSizeType = isset($roomSizeTypes[$this->room_size_type]) && !empty($this->room_size_type) ? $roomSizeTypes[$this->room_size_type] : $this->room_size_type;

        return $roomSizeType;
    }


    public function propertyRoomType()
    {
        return $this->hasOne('App\Models\PropertyRoomType', 'id', 'room_type_id')->select(['id', 'name', 'status', 'language_key']);
    }

    public function propertyRoomRateMapping()
    {
        return $this->hasMany('App\Models\PropertyRoomRateMapping', 'room_id', 'id')->select(['id', 'room_id', 'room_rate_id', 'description', 'rack_rate', 'included_occupancy','connected_rate_id','is_affected_price','affect_price_action_type','affect_price_type','affect_price_value']);
    }

    public function propertyRoomBedGroup()
    {
        return $this->hasMany('App\Models\PropertyRoomBed', 'room_id', 'id')->select(['id', 'room_id', 'bed_group', 'count', 'bed_type_id', 'status']);
    }

    public function propertyRoomFactMapping()
    {
        return $this->hasMany('App\Models\PropertyRoomFactMapping', 'room_id', 'id')->select(['id', 'room_id', 'fact_id', 'property_id', 'is_feature']);
    }

    public function propertyRoomPhotoMapping()
    {
        return $this->hasMany('App\Models\PropertyRoomPhotoMapping', 'room_id', 'id')->select(['id', 'room_id', 'photo_id', 'property_id']);
    }

    public function propertyRoomDefaultPhoto()
    {
        return $this->hasOne('App\Models\PropertyRoomPhotoMapping', 'room_id', 'id')->select(['id', 'room_id', 'photo_id', 'property_id']);
    }

    public function propertyRoomViewMapping()
    {
        return $this->hasMany('App\Models\PropertyRoomViewMapping', 'room_id', 'id')->select(['id', 'room_id', 'room_view_type_id']);
    }

    public function propertyRoomConnected()
    {
        return $this->hasMany('App\Models\PropertyRoomConnected', 'room_id', 'id')->select(['id', 'room_id', 'connected_room_id']);
    }

    public function propertyWebRoomMapping()
    {
        return $this->hasOne('App\Models\PropertyWebRoomMapping', 'property_room_id', 'id')->select(['id', 'property_id', 'property_web_id', 'property_room_id']);
    }

    public function smokingPreference()
    {
        return $this->hasMany('App\Models\PropertyRoomFactMapping', 'room_id', 'id')
            ->whereIn('fact_id',  [684,685])->select();
    }
}
