<?php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class CustomerRating
 *
 * @package App
 * @property double $position
 * @property double $infrastructure
 * @property double $transport_hub
 * @property double $planning
 * @property double $price_quality
 * @property tinyInteger $enabled
 * @property string $residental_complex
 * @property-write mixed $residental_complex_id
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerRating newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerRating newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\CustomerRating onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerRating query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\CustomerRating withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\CustomerRating withoutTrashed()
 * @mixin \Eloquent
 */
class CustomerRating extends Model
{
    use SoftDeletes;

    protected $fillable = ['position', 'infrastructure', 'transport_hub', 'planning', 'price_quality', 'enabled', 'residental_complex_id'];
    protected $hidden = ['created_at', 'updated_at', "id"];
    
    

    /**
     * Set attribute to date format
     * @param $input
     */
    public function setPositionAttribute($input)
    {
        if ($input != '') {
            $this->attributes['position'] = $input;
        } else {
            $this->attributes['position'] = null;
        }
    }

    /**
     * Set attribute to date format
     * @param $input
     */
    public function setInfrastructureAttribute($input)
    {
        if ($input != '') {
            $this->attributes['infrastructure'] = $input;
        } else {
            $this->attributes['infrastructure'] = null;
        }
    }

    /**
     * Set attribute to date format
     * @param $input
     */
    public function setTransportHubAttribute($input)
    {
        if ($input != '') {
            $this->attributes['transport_hub'] = $input;
        } else {
            $this->attributes['transport_hub'] = null;
        }
    }

    /**
     * Set attribute to date format
     * @param $input
     */
    public function setPlanningAttribute($input)
    {
        if ($input != '') {
            $this->attributes['planning'] = $input;
        } else {
            $this->attributes['planning'] = null;
        }
    }

    /**
     * Set attribute to date format
     * @param $input
     */
    public function setPriceQualityAttribute($input)
    {
        if ($input != '') {
            $this->attributes['price_quality'] = $input;
        } else {
            $this->attributes['price_quality'] = null;
        }
    }

    /**
     * Set to null if empty
     * @param $input
     */
    public function setResidentalComplexIdAttribute($input)
    {
        $this->attributes['residental_complex_id'] = $input ? $input : null;
    }
    
    public function residental_complex()
    {
        return $this->belongsTo(ResidentialComplex::class, 'residental_complex_id')->withTrashed();
    }
    
}
