<?php

namespace Opencart\Extension\Alsendo\DTO\ConfigurationRequests;

require_once(DIR_EXTENSION . 'alsendo/src/DTO/ConfigurationRequests/CoreConfigurationRequestDTO.php');

class UpdateShippingSettingsTemplateRequestDTO
{
    public ?int $id = null;
    public ?string $name = null;
    public ?string $packageType = null;
    public ?string $length = null;
    public ?string $width = null;
    public ?string $height = null;
    public ?string $weight = null;
    public ?string $cashOnDelivery = null;
    public ?string $declaredValue = null;
    public ?string $shipmentContent = null;
    public ?string $defaultContentCustomText = null;
    public ?string $pickupType = null;
    public ?array $selectedServices = null;
    public ?bool $nonStandard = null;

    public static function fromCoreConfigurationRequestDTO(CoreConfigurationRequestDTO $coreDto): self
    {
        $dto = new self();
        $dto->id = $coreDto->id;
        $dto->name = $coreDto->name;
        $dto->packageType = $coreDto->packageType;
        $dto->length = $coreDto->length;
        $dto->width = $coreDto->width;
        $dto->height = $coreDto->height;
        $dto->weight = $coreDto->weight;
        $dto->cashOnDelivery = $coreDto->cashOnDelivery;
        $dto->declaredValue = $coreDto->declaredValue;
        $dto->shipmentContent = $coreDto->shipmentContent;
        $dto->defaultContentCustomText = $coreDto->defaultContentCustomText;
        $dto->pickupType = $coreDto->pickupType;
        $dto->selectedServices = $coreDto->selectedServices ?? [];
        $dto->nonStandard = isset($coreDto->nonStandard) && $coreDto->nonStandard == '1';
        return $dto;
    }

    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'package_type' => $this->packageType,
            'length' => $this->length,
            'width' => $this->width,
            'height' => $this->height,
            'weight' => $this->weight,
            'cash_on_delivery' => $this->cashOnDelivery,
            'declared_value' => $this->declaredValue,
            'shipment_content' => $this->shipmentContent,
            'default_content_custom_text' => $this->defaultContentCustomText,
            'pickup_type' => $this->pickupType,
            'selected_services' => $this->selectedServices,
            'non_standard' => $this->nonStandard,
        ];
    }
}
