<?php
/*
 *  Copyright 2023.  Baks.dev <admin@baks.dev>
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is furnished
 *  to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in all
 *  copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */

declare(strict_types=1);

namespace BaksDev\Products\Sign\UseCase\Admin\New\Tests;

use BaksDev\Products\Product\Type\Id\ProductUid;
use BaksDev\Products\Product\Type\Offers\ConstId\ProductOfferConst;
use BaksDev\Products\Product\Type\Offers\Variation\ConstId\ProductVariationConst;
use BaksDev\Products\Product\Type\Offers\Variation\Modification\ConstId\ProductModificationConst;
use BaksDev\Products\Sign\Entity\ProductSign;
use BaksDev\Products\Sign\Repository\CurrentEvent\ProductSignCurrentEventInterface;
use BaksDev\Products\Sign\Type\Id\ProductSignUid;
use BaksDev\Products\Sign\Type\Status\ProductSignStatus\Collection\ProductSignStatusCollection;
use BaksDev\Products\Sign\Type\Status\ProductSignStatus\ProductSignStatusDone;
use BaksDev\Products\Sign\Type\Status\ProductSignStatus\ProductSignStatusNew;
use BaksDev\Products\Sign\UseCase\Admin\New\Code\ProductSignCodeDTO;
use BaksDev\Products\Sign\UseCase\Admin\New\ProductSignDTO;
use BaksDev\Products\Sign\UseCase\Admin\New\ProductSignHandler;
use BaksDev\Users\Profile\UserProfile\Type\Id\UserProfileUid;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\Attribute\When;

/**
 * @group products-sign
 * @depends BaksDev\Products\Sign\UseCase\Admin\New\Tests\ProductSignNewHandleTest::class
 */
#[When(env: 'test')]
final class ProductSignEditHandleTest extends KernelTestCase
{
    public function testUseCase(): void
    {
        /**
         * Инициируем статус для итератора тегов
         * @var ProductSignStatusCollection $status
         */
        $status = self::getContainer()->get(ProductSignStatusCollection::class);
        $status->cases();

        /** @var ProductSignCurrentEventInterface $ProductSignCurrentEvent */
        $ProductSignCurrentEvent = self::getContainer()->get(ProductSignCurrentEventInterface::class);
        $ProductSignEvent = $ProductSignCurrentEvent->findByProductSign(ProductSignUid::TEST);
        self::assertNotNull($ProductSignEvent);


        /** @see ProductSignDTO */

        $ProductSignDTO = new ProductSignDTO($UserProfileUid = clone new UserProfileUid());
        $ProductSignEvent->getDto($ProductSignDTO);
        self::assertSame($UserProfileUid, $ProductSignDTO->getProfile());

        self::assertTrue($ProductSignDTO->getStatus()->equals(ProductSignStatusNew::class));
        $ProductSignDTO->setStatus(ProductSignStatusDone::class);

        /** @see ProductSignCodeDTO */

        $ProductSignCodeDTO = $ProductSignDTO->getCode();

        self::assertEquals('code', $ProductSignCodeDTO->getCode());
        $ProductSignCodeDTO->setCode('code_edit');

        self::assertNotNull($ProductSignCodeDTO->getQr());

        self::assertTrue($ProductSignCodeDTO->getProduct()->equals(ProductUid::TEST));
        $ProductSignCodeDTO->setProduct(clone $ProductSignCodeDTO->getProduct());

        self::assertTrue($ProductSignCodeDTO->getOffer()->equals(ProductOfferConst::TEST));
        $ProductSignCodeDTO->setOffer(clone $ProductSignCodeDTO->getOffer());

        self::assertTrue($ProductSignCodeDTO->getVariation()->equals(ProductVariationConst::TEST));
        $ProductSignCodeDTO->setVariation(clone $ProductSignCodeDTO->getVariation());

        self::assertTrue($ProductSignCodeDTO->getModification()->equals(ProductModificationConst::TEST));
        $ProductSignCodeDTO->setModification(clone $ProductSignCodeDTO->getModification());


        /** @var ProductSignHandler $ProductSignHandler */
        $ProductSignHandler = self::getContainer()->get(ProductSignHandler::class);
        $handle = $ProductSignHandler->handle($ProductSignDTO);

        self::assertTrue(($handle instanceof ProductSign), $handle.': Ошибка ProductSign');

    }
}