<?php

namespace App;

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

/**
 * Class Price
 *
 * @package App
 * @property string $residential_complex
 * @property string $section
 * @property string $room_count
 * @property string $room_type
 * @property string $min_space
 * @property string $max_space
 * @property string $price_per_squera_meter
 * @property string $price_per_squera_meter_max
 * @property string $min_price
 * @property string $max_price
 */
class PlanningPrice extends Model
{
    use SoftDeletes;

    protected $table = 'planning_prices';

    protected $fillable = [
        'min_space',
        'max_space',
        'price_per_squera_meter',
        'min_price',
        'max_price',
        'residential_complex_id',
        'section_id',
        'room_count_id',
        'number_of_apartments',
        'price_per_squera_meter_max',
        'room_type_id'
    ];
    protected $hidden = [];

    /**
     * Set to null if empty
     * @param $input
     */
    public function setResidentialComplexIdAttribute($input)
    {
        $this->attributes['residential_complex_id'] = $input ? $input : null;
    }

    /**
     * Set to null if empty
     * @param $input
     */
    public function setSectionIdAttribute($input)
    {
        $this->attributes['section_id'] = $input ? $input : null;
    }

    /**
     * Set to null if empty
     * @param $input
     */
    public function setRoomCountIdAttribute($input)
    {
        $this->attributes['room_count_id'] = $input ? $input : null;
    }

    /**
     * Set to null if empty
     * @param $input
     */
    public function setRoomTypeIdAttribute($input)
    {
        $this->attributes['room_type_id'] = $input ? $input : null;
    }

    public function residential_complex()
    {
        return $this->belongsTo(ResidentialComplex::class, 'residential_complex_id')->withTrashed();
    }

    public function section()
    {
        return $this->belongsTo(Section::class, 'section_id')->withTrashed();
    }

    public function room_count()
    {
        return $this->belongsTo(RoomCount::class, 'room_count_id')->withTrashed();
    }

    public function room_type()
    {
        return $this->belongsTo(RoomType::class, 'room_type_id')->withTrashed();
    }
}
