<?php

namespace domain\PointSale\SharedPointSale;

use domain\_\AbstractManager;
use domain\PointSale\PointSale\PointSale;
use domain\Producer\Producer\Producer;
use domain\User\User\User;

class SharedPointSaleManager extends AbstractManager
{
    protected SharedPointSaleBuilder $sharedPointSaleBuilder;

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

    public function createSharedPointSale(PointSale $pointSale, Producer $producerWithSharing, User $createdBy): SharedPointSale
    {
        $sharedPointSale = $this->sharedPointSaleBuilder->instanciateSharedPointSale($pointSale, $producerWithSharing, $createdBy);
        $this->sharedPointSaleBuilder->create($sharedPointSale);
        return $sharedPointSale;
    }

    public function confirmSharedPointSale(SharedPointSale $sharedPointSale, PointSale $pointSaleWithSharing, User $confirmedBy): bool
    {
        $this->sharedPointSaleBuilder->initConfirmSharedPointSale($sharedPointSale, $pointSaleWithSharing, $confirmedBy);
        return $this->sharedPointSaleBuilder->update($sharedPointSale);
    }

    public function declineSharedPointSale(SharedPointSale $sharedPointSale, User $declinedBy): bool
    {
        $this->sharedPointSaleBuilder->initDeclineSharedPointSale($sharedPointSale, $declinedBy);
        return $this->sharedPointSaleBuilder->update($sharedPointSale);
    }
}