<?php

namespace LaraBB\Group\Tasks;

use Illuminate\Database\Eloquent\Collection;
use LaraBB\Group\Models\Group;

/**
 * Class GetGroupTask
 * @package LaraBB\Group\Tasks
 */
class FindTask
{
    /**
     * GetGroupTask constructor.
     * @param Group $group
     */
    public function __construct(private readonly Group $group)
    {
    }

    /**
     * @param array $with
     * @return array|Collection
     */
    public function all(array $with = []): array|Collection
    {
        return $this->group->query()->with($with)->get();
    }

    /**
     * @param string $uuid
     * @param array $with
     * @return Group
     */
    public function byUuid(string $uuid, array $with = []): Group
    {
        return $this->group->query()->with($with)->where('uuid', $uuid)->get()->first();
    }

    /**
     * @param string $name
     * @param array $with
     * @return Group
     */
    public function byName(string $name, array $with = []): Group
    {
        return $this->group->query()->with($with)->where('name', $name)->get()->first();
    }
}
