<?php

namespace App\Models\Backoffice;

use App\Models\Backoffice\Support\ContentTypeModel;
use App\Models\Backoffice\Traits\LanguageSupportTrait;
use MatanYadaev\EloquentSpatial\Objects\Point;
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;

class Block extends ContentTypeModel
{
    use LanguageSupportTrait;
    use HasSpatial;

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

    protected $dates = []; // dates

    protected $casts = [
        'is_active' => 'boolean',
        'link' => 'json',
        'location' => Point::class
    ];

    public function slider()
    {
        return $this->belongsToMany(SliderItem::class)->withPivot('position');
    }

    public function page()
    {
        return $this->belongsToMany(Page::class, 'page_block')->withPivot('position');
    }

    public function mediaItemsReferences()
    {
        return $this->morphToMany(MediaItem::class, 'referenceable', 'media_item_references')->withTimestamps();
    }
    
    public function image() {
        return $this->belongsTo(MediaItem::class);
    }
}
