<?php

    namespace App\Models;

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

    class Product extends ContentTypeModel
    {
        use LanguageSupportTrait;

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

        protected $dates = []; // dates

        protected $casts = [
            'other_link' => 'array',
            'buy_now_link' => 'array',
        ];

        public function productGroup()
        {
            return $this->belongsTo(ProductGroup::class);
        }

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

        public function bluetoothVersion()
        {
            return $this->belongsTo(BluetoothVersion::class);
        }

        public function otherImages()
        {
            return $this->belongsToMany(MediaItem::class);
        }

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

        
        public function relatedProducts()
        {
            return $this->belongsToMany(Product::class, 'related_products', 'product_id', 'related_product_id')->withPivot('position')->withTimestamps();
        }
        
        public function productTags()
        {
            return $this->belongsToMany(Tag::class)->withTimestamps();
        }
        
        public function productCategories()
        {
            return $this->belongsToMany(Category::class)->withTimestamps();
        }
        
        public function components()
        {
            return $this->belongsToMany(Component::class)->withPivot('position')->withTimestamps();
        }

        public function imageLinks()
        {
            return $this->belongsToMany(ImageLink::class)->withPivot('position')->withTimestamps();
        }
        
        public function otherVersions()
        {
            return $this->belongsToMany(Product::class, 'product_other_version', 'product_id', 'other_product_id')->withPivot('position')->withTimestamps();
        }

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