<?php

namespace App;

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

/**
 * Class Marker
 *
 * @package App
 * @property string $latitude
 * @property string $longitude
 * @property string $address_latitude
 * @property string $address_longitude
 * @property string $address
 * @property string $infrastructure_type
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\ResidentialComplex[] $residential_complexes
 * @property-write mixed $infrastructure_type_id
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Marker newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Marker newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Marker onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Marker query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\Marker withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Marker withoutTrashed()
 * @mixin \Eloquent
 */
class Marker extends Model
{
    const PAGINATE = 20;
    const MARKER_TYPES = 'marker_types';
    const MARKERS = 'markers';

    use SoftDeletes;

    protected $fillable = [
        'latitude',
        'longitude',
        'address_address',
        'address_latitude',
        'address_longitude',
        'infrastructure_type_id',
        'street_name'
    ];

    protected $hidden = [];
    
    

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

    public function residential_complexes()
    {
        return $this->belongsToMany(ResidentialComplex::class, 'residential_complex_markers')->withTrashed();
    }
}
