<?php

namespace App\Models;

use App\Libs\Database\Eloquent\ContentTypeModel;
use App\Models\GenericBackoffice\Traits\LanguageSupportTrait;
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
use MatanYadaev\EloquentSpatial\Objects\Point;
use App\Traits\Indexable;
use App\Traits\FcmSubscribable;
use App\Traits\Favouritable;
use App\Traits\WithShareUrl;


class Collection extends ContentTypeModel
{
    use LanguageSupportTrait;
    use HasSpatial;
    use Indexable;
    use FcmSubscribable;
    use Favouritable;
    use WithShareUrl;


    protected $hidden        = ['languages', "websites"];
    protected $with          = ['languages', "websites"];
    protected $dates         = []; // dates
    protected $casts = [
        'map_position' => Point::class
    ];


    public function image()
    {
        return $this->belongsTo(MediaItem::class);
    }

    public function exploreCollectionImage()
    {
        return $this->belongsTo(MediaItem::class);
    }

    public function city()
    {
        return $this->belongsTo(City::class);
    }

    public function cityZone()
    {
        return $this->belongsTo(CityZone::class);
    }

    public function artists()
    {
        return $this->belongsToMany(Artist::class);
    }

    public function blocks()
    {
        return $this->belongsToMany(Block::class, 'collection_block')->withPivot('position');
    }

    public function exhibitions()
    {
        return $this->belongsToMany(Exhibition::class);
    }

    public function catalogue()
    {
        return $this->hasOne(CollectionCatalogue::class, 'id', 'collection_catalogue_id');
    }
}
