<?php

    namespace App\Models;

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

    class Firmware extends ContentTypeModel
    {
        use LanguageSupportTrait;

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

        protected $casts = ['reference' => 'array'];

        protected $table = 'firmwares';

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

        public function authors()
        {
            return $this->belongsToMany(WebLink::class, 'firmware_reference', 'firmware_id', 'web_link_id')->withPivot('position')->withTimestamps();
        }

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

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

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