<?php

    namespace App\Models;

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

    class Classification extends ContentTypeModel
    {
        CONST TYPE_VISITABLE                = 178;
        CONST TYPE_NOT_VISITABLE            = 179;
        CONST TYPE_VISITABLE_NOT_VISIBLE    = 296;

        use LanguageSupportTrait;

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

        protected $fillable = [
            'external_id',
            'parent_id'
        ];

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

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

        public function scopeClassificationFilters($query) {
            return $query->whereIn('external_id', [
                self::TYPE_VISITABLE,
                self::TYPE_NOT_VISITABLE,
                self::TYPE_VISITABLE_NOT_VISIBLE
            ]);
        }
        
        public function isVisitable() {
            return $this->external_id === self::TYPE_VISITABLE;
        }
        public function isNotVisitable() {
            return $this->external_id === self::TYPE_NOT_VISITABLE;
        }
        public function isVisitableNotVisible() {
            return $this->external_id === self::TYPE_VISITABLE_NOT_VISIBLE;
        }
    }
