<?php

namespace App\Repositories\Shop;

use App\Models\Shop\Article;

class ArticleSiblings
{
    public static function getSiblingsIDs($id)
    {
        return self::getSiblings($id)->pluck('id')->toArray();
    }

    public static function getSiblingsDescriptions($id)
    {
        $data = [];
        $siblings = self::getSiblings($id);
        foreach ($siblings as $sibling) {
            if ($sibling->description && ($sibling->article_nature->name ?? false)) {
                $data[strtolower($sibling->article_nature->name)] = $sibling->description;
            }
        }

        return $data ?? false;
    }

    public static function getSiblings($id)
    {
        return Article::with([
            'siblings' => function ($query) use ($id) {
                $query->where('id', '!=', $id);
            },
        ])->find($id)->siblings;
    }
}
