<?php

namespace App\Models;

use App\Libs\Database\Eloquent\ContentTypeModel;
use App\Models\GenericBackoffice\Benefit;
use App\Models\GenericBackoffice\ClientLogo;
use App\Models\GenericBackoffice\KeyMessage;
use App\Models\GenericBackoffice\ProjectDetail;
use App\Models\GenericBackoffice\ServiceSolution;
use App\Models\GenericBackoffice\SimpleLink;
use App\Models\GenericBackoffice\Phrase;
use App\Models\GenericBackoffice\TeamMember;
use App\Models\GenericBackoffice\Traits\LanguageSupportTrait;

class Block extends ContentTypeModel
{
    use LanguageSupportTrait;

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

    protected $dates = []; // dates

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

    public function blockImages()
    {
        return $this->belongsToMany(MediaItem::class, 'block_media_item')->withPivot('position')->orderBy('position');
    }

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

    public function blockSimpleLinks()
    {
        return $this->belongsToMany(SimpleLink::class, 'block_simple_link')->withPivot('position')->orderBy('position');
    }

    public function blockKeyMessages()
    {
        return $this->belongsToMany(KeyMessage::class, 'block_key_message')->withPivot('position')->orderBy('position');
    }

    public function blockClientLogos()
    {
        return $this->belongsToMany(ClientLogo::class, 'block_client_logo')->withPivot('position')->orderBy('position');
    }

    public function blockServicesSolutions()
    {
        return $this->belongsToMany(ServiceSolution::class, 'block_service_solution')->withPivot('position')->orderBy('position');
    }

    public function blockBenefits()
    {
        return $this->belongsToMany(Benefit::class, 'block_benefit')->withPivot('position')->orderBy('position');
    }

    public function blockPhrases()
    {
        return $this->belongsToMany(Phrase::class, 'block_phrase')->withPivot('position')->orderBy('position');
    }

    public function blockProjectDetails()
    {
        return $this->belongsToMany(ProjectDetail::class, 'block_project_detail')->withPivot('position')->orderBy('position');
    }

    public function blockBlocks()
    {
        return $this->belongsToMany(Block::class, 'block_block', 'parent_block_id')->withPivot('position')->orderBy('position');
    }

    public function blockAuthor()
    {
        return $this->belongsToMany(TeamMember::class, 'block_team_member')->withPivot('position')->orderBy('position');
    }
}
