<?php

    namespace App\Models;

    use App\Libs\Database\Eloquent\ContentTypeModel;
    use App\Models\GenericBackoffice\Traits\LanguageSupportTrait;
    use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;

    class Property extends ContentTypeModel
    {
        use LanguageSupportTrait, SpatialTrait;

        protected $hidden = ['languages', "websites"];
        protected $with = ['languages', "websites"];

        protected $fillable = [
            'external_id',
            'external_reference',
            'local_id',
            'address',
            'geolocation',
        ];

        protected $spatialFields = [ 'geolocation' ];

        public function themes()
        {
            return $this->belongsToMany(Theme::class)->withPivot('position')->withTimestamps();
        }

        public function typologies()
        {
            return $this->belongsToMany(Typology::class)->withPivot('position')->withTimestamps();
        }

        public function classifications()
        {
            return $this->belongsToMany(Classification::class)->withPivot('position')->withTimestamps();
        }

        public function accesses()
        {
            return $this->belongsToMany(Access::class)->withPivot('position')->withTimestamps();
        }

        public function images()
        {
            return $this->belongsToMany(PropertyImage::class)->withPivot('position')->withTimestamps();
        }

        public function epigraphs()
        {
            return $this->belongsToMany(Epigraph::class)->withPivot(['position', 'found_local_id'])->withTimestamps();
        }

        public function propertyType()
        {
            return $this->belongsTo(PropertyType::class);
        }

        public function chronologies()
        {
            return $this->belongsToMany(Chronology::class)->withPivot('position')->withTimestamps();
        }

        public function qrcode()
        {
            return $this->hasOne(QrCode::class, 'external_property_id', 'external_id');
        }

        public function audioVisuals()
        {
            return $this->belongsToMany(AudioVisual::class)->withPivot('position')->withTimestamps();
        }

        public function location()
        {
            return $this->belongsTo(Location::class, 'local_id');
        }
    }
