<?php

namespace App\Models;

use App\Models\Backoffice\MediaItem;
use App\Models\Backoffice\Support\ContentTypeModel;
use App\Models\Backoffice\Traits\LanguageSupportTrait;

class Article extends ContentTypeModel
{
    use LanguageSupportTrait;

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


    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function relatedArticles()
    {
        return $this->belongsToMany(
            Article::class,
            'article_related',
            'article_id',
            'related_article_id'
        )->withPivot('position')->orderBy('position');
    }

    public function imageTextBlock()
    {
        return $this->belongsTo(MediaItem::class, 'image_text_block_id');
    }

    public function imageMagazine()
    {
        return $this->belongsTo(MediaItem::class, 'image_magazine_id');
    }

    public function featuredImage()
    {
        return $this->belongsTo(MediaItem::class, 'featured_image_id');
    }
}
