<?php

namespace common\logic\Subscription\Subscription\Service;

use common\logic\AbstractBuilder;
use common\logic\Distribution\Distribution\Repository\DistributionRepository;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\Subscription\Model\Subscription;

class SubscriptionBuilder extends AbstractBuilder
{
    protected DistributionRepository $distributionRepository;

    public function loadDependencies(): void
    {
        $this->distributionRepository = $this->loadService(DistributionRepository::class);
    }

    public function instanciateSubscription(): Subscription
    {
        $subscription = new Subscription();

        return $subscription;
    }

    public function createSubscription(): Subscription
    {
        $subscription = $this->instanciateSubscription();
        $this->saveCreate($subscription);

        return $subscription;
    }

    public function deleteSubscription(Subscription $subscription): void
    {
        ProductSubscription::deleteAll(['id_subscription' => $subscription->id]);
        $this->delete($subscription);
    }
}