<?php

namespace App;

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

/**
 * Class SecretBuyerRating
 *
 * @package App
 * @property double $position
 * @property double $infrastructure
 * @property double $transport_hub
 * @property double $planning
 * @property double $price_quality
 * @property tinyInteger $enabled
 * @property string $description
 * @property string $residental_complex
 * @property string $youtube_link
 * @property string $image
 * @property-write mixed $residental_complex_id
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SecretBuyerRating newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SecretBuyerRating newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\SecretBuyerRating onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SecretBuyerRating query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\SecretBuyerRating withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\SecretBuyerRating withoutTrashed()
 * @mixin \Eloquent
 */
class SecretBuyerRating extends Model
{
    use SoftDeletes;
    protected $fillable = [
        'position',
        'infrastructure',
        'transport_hub',
        'planning',
        'price_quality',
        'enabled',
        'youtube_link',
        'image',
        'description',
        'residental_complex_id',
        'created_at'
    ];
    protected $hidden = [];

    /**
     * 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();
    }
}
