<?php

namespace LaraBB\Group\Tasks;

use Exception;
use Illuminate\Database\Eloquent\Builder;
use LaraBB\Group\Models\Group;

/**
 * Class DestroyGroupTask
 * @package LaraBB\Group\Tasks
 */
class DestroyTask
{
    /**
     * @var
     */
    private Builder|Group $query;

    /**
     * DestroyGroupTask constructor.
     * @param Group $group
     */
    public function __construct(private readonly Group $group)
    {

    }

    /**
     * @return bool|null
     * @throws Exception
     */
    public function run(): ?bool
    {
        return $this->query->delete();
    }

    /**
     * @param $uuid
     * @return bool|null
     * @throws Exception
     */
    public function byUuid($uuid): ?bool
    {
        $this->query = $this->group->query()->where('uuid', $uuid);

        return $this->run();
    }
}
