<?php

declare(strict_types=1);

namespace Gls\GlsPoland\PrestaShop\Message;

use Gls\GlsPoland\Carrier\CarrierType;
use Gls\GlsPoland\Carrier\ParcelShopType;

class CreateShopDeliveryCarrierCommand extends AbstractCreateCarrierCommand
{
    private $type;
    private $parcelShopType;

    /**
     * @param string[] $countryIsoCodes
     */
    public function __construct(?string $name = null, array $countryIsoCodes = [], $parcelShopType = null)
    {
        $this->type = CarrierType::from(CarrierType::SHOP_DELIVERY);
        $this->setParcelShopType($parcelShopType);

        parent::__construct($name, ...$countryIsoCodes);
    }

    public function getType(): CarrierType
    {
        return $this->type;
    }

    public function isCashOnDelivery(): bool
    {
        return false;
    }

    public function getParcelShopType(): ?ParcelShopType
    {
        return ParcelShopType::tryFrom($this->parcelShopType);
    }

    public function setParcelShopType($parcelShopType): self
    {
        if ($parcelShopType instanceof ParcelShopType) {
            $parcelShopType = $parcelShopType->getValue();
        }

        $this->parcelShopType = ParcelShopType::tryFrom($parcelShopType);
        $this->parcelShopType = null !== $this->parcelShopType ? $this->parcelShopType->getValue() : null;

        return $this;
    }
}
