<?php

namespace Modules\Feature\Services;

use Illuminate\Http\Request;
use Modules\Feature\Interfaces\FeatureRepositoryInterface;
use Modules\Package\Interfaces\PackageRepositoryInterface;
use Modules\Package\Models\Package;

class FeatureService
{
    public function __construct(
        private FeatureRepositoryInterface $featureRepository
    )
    {}

    public function get(array $request)
    {
        $builder = $this->featureRepository->get($request);

        if (@$request['featureable_id'])
        {
            $builder->where('featureable_id',$request['featureable_id']);
        }
        if (isset($request['featureable_type']))
        {
            $builder->where('featureable_type',$request['featureable_type']);
        }

        return $builder->get();
    }
    public function create(array $request)
    {
        $this->deleteAll($request);
        $this->featureRepository->create($request);
    }

    public function deleteAll(array $request):void
    {
        $this->featureRepository->deleteAll($request);
    }
}
