<?php

namespace Opencart\Extension\Alsendo\DTO\ConfigurationRequests;

class CoreConfigurationRequestDTO
{
    public ?string $action = null;
    public ?string $userToken = null;
    public ?string $region = null;
    public ?string $appId = null;
    public ?string $appSecret = null;
    public ?string $token = null;
    public ?string $apiKey = null;
    public ?string $roClientId = null;
    public ?string $roClientSecret = null;
    public ?string $sandbox = null;
    public ?string $roSandbox = null;
    public ?string $czSandbox = null;
    public ?int $id = null;
    public ?array $selectedServices = null;
    public ?string $nonStandard = null;
    public ?string $name = null;
    public ?string $companyName = null;
    public ?string $fullName = null;
    public ?string $street = null;
    public ?string $buildingNumber = null;
    public ?string $apartmentNumber = null;
    public ?string $block = null;
    public ?string $entrance = null;
    public ?string $floor = null;
    public ?string $postalCode = null;
    public ?string $city = null;
    public ?string $country = null;
    public ?string $phoneNumber = null;
    public ?string $email = null;
    public ?string $bankAccountNumber = null;
    public ?string $bankCode = null;
    public ?string $additionalBankAccountNumber = null;
    public ?string $addressType = null;
    public ?string $externalId = 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 ?string $inpostDefaultPoint = null;
    public ?string $dhlDefaultPoint = null;
    public ?string $orlenDefaultPoint = null;
    public ?string $pocztaPolskaDefaultPoint = null;
    public ?string $dpdDefaultPoint = null;
    public ?string $upsDefaultPoint = null;
    public ?string $balikovnaDefaultPoint = null;
    public ?string $glsDefaultPoint = null;
    public ?string $pplDefaultPoint = null;
    public ?string $zasilkovnaDefaultPoint = null;
    public ?string $samedayDefaultPoint = null;
    public ?string $fanCourierDefaultPoint = null;
    public ?string $cargusDefaultPoint = null;
    public ?string $pickupHourFrom = null;
    public ?string $pickupHourTo = null;
    public ?int $autoCompleteContentForOrderId = null;
    public bool $autoDeclaredValue = false;
    public bool $samedayDispatch = false;

    public static function createFromPayload(array $payload): self
    {
        $dto = new self();
        
        $dto->action = $payload['action'] ?? null;
        $dto->userToken = $payload['user_token'] ?? null;
        $dto->region = $payload['region'] ?? null;
        $dto->appId = $payload['app_id'] ?? null;
        $dto->appSecret = $payload['app_secret'] ?? null;
        $dto->token = $payload['token'] ?? null;
        $dto->apiKey = $payload['api_key'] ?? null;
        $dto->roClientId = $payload['ro_client_id'] ?? null;
        $dto->roClientSecret = $payload['ro_client_secret'] ?? null;
        $dto->sandbox = $payload['sandbox'] ?? null;
        $dto->roSandbox = $payload['ro_sandbox'] ?? null;
        $dto->czSandbox = $payload['cz_sandbox'] ?? null;
        $dto->id = isset($payload['id']) ? (int)$payload['id'] : null;
        $dto->selectedServices = $payload['selected_services'] ?? null;
        $dto->nonStandard = $payload['non_standard'] ?? null;
        $dto->name = $payload['name'] ?? null;
        $dto->companyName = $payload['company_name'] ?? null;
        $dto->fullName = $payload['full_name'] ?? null;
        $dto->street = $payload['street'] ?? null;
        $dto->buildingNumber = $payload['building_number'] ?? null;
        $dto->apartmentNumber = $payload['apartment_number'] ?? null;
        $dto->block = $payload['block'] ?? null;
        $dto->entrance = $payload['entrance'] ?? null;
        $dto->floor = $payload['floor'] ?? null;
        $dto->postalCode = $payload['postal_code'] ?? null;
        $dto->city = $payload['city'] ?? null;
        $dto->country = $payload['country'] ?? null;
        $dto->phoneNumber = $payload['phone_number'] ?? null;
        $dto->email = $payload['email'] ?? null;
        $dto->bankAccountNumber = $payload['bank_account_number'] ?? null;
        $dto->bankCode = $payload['bank_code'] ?? null;
        $dto->additionalBankAccountNumber = $payload['additional_bank_account_number'] ?? null;
        $dto->addressType = $payload['address_type'] ?? null;
        $dto->externalId = $payload['external_id'] ?? null;
        $dto->packageType = $payload['package_type'] ?? null;
        $dto->length = $payload['length'] ?? null;
        $dto->width = $payload['width'] ?? null;
        $dto->height = $payload['height'] ?? null;
        $dto->weight = $payload['weight'] ?? null;
        $dto->cashOnDelivery = $payload['cash_on_delivery'] ?? null;
        $dto->declaredValue = $payload['declared_value'] ?? null;
        $dto->shipmentContent = $payload['shipment_content'] ?? null;
        $dto->defaultContentCustomText = $payload['default_content_custom_text'] ?? null;
        $dto->pickupType = $payload['pickup_type'] ?? null;
        $dto->inpostDefaultPoint = $payload['inpost_default_point'] ?? null;
        $dto->dhlDefaultPoint = $payload['dhl_default_point'] ?? null;
        $dto->orlenDefaultPoint = $payload['orlen_default_point'] ?? null;
        $dto->pocztaPolskaDefaultPoint = $payload['poczta_polska_default_point'] ?? null;
        $dto->dpdDefaultPoint = $payload['dpd_default_point'] ?? null;
        $dto->upsDefaultPoint = $payload['ups_default_point'] ?? null;
        $dto->balikovnaDefaultPoint = $payload['balikovna_default_point'] ?? null;
        $dto->glsDefaultPoint = $payload['gls_default_point'] ?? null;
        $dto->pplDefaultPoint = $payload['ppl_default_point'] ?? null;
        $dto->zasilkovnaDefaultPoint = $payload['zasilkovna_default_point'] ?? null;

        $dto->samedayDefaultPoint = $payload['sameday_default_point'] ?? null;
        $dto->fanCourierDefaultPoint = $payload['fan_courier_default_point'] ?? null;
        $dto->cargusDefaultPoint = $payload['cargus_default_point'] ?? null;

        $dto->pickupHourFrom = $payload['pickup_hour_from'] ?? null;
        $dto->pickupHourTo = $payload['pickup_hour_to'] ?? null;
        $dto->autoCompleteContentForOrderId = !empty($payload['auto_complete_content_for_order_id']) ? (int)$payload['auto_complete_content_for_order_id'] : null;
        $dto->autoDeclaredValue = isset($payload['auto_declared_value']) && (bool) $payload['auto_declared_value'];
        $dto->samedayDispatch = isset($payload['sameday_dispatch']) && (bool) $payload['sameday_dispatch'];

        return $dto;
    }

    public function toArray(): array
    {
        return [
            'action' => $this->action,
            'user_token' => $this->userToken,
            'region' => $this->region,
            'app_id' => $this->appId,
            'app_secret' => $this->appSecret,
            'token' => $this->token,
            'api_key' => $this->apiKey,
            'ro_client_id' => $this->roClientId,
            'ro_client_secret' => $this->roClientSecret,
            'sandbox' => $this->sandbox,
            'id' => $this->id,
            'selected_services' => $this->selectedServices,
            'non_standard' => $this->nonStandard,
            'name' => $this->name,
            'company_name' => $this->companyName,
            'full_name' => $this->fullName,
            'street' => $this->street,
            'building_number' => $this->buildingNumber,
            'apartment_number' => $this->apartmentNumber,
            'block' => $this->block,
            'entrance' => $this->entrance,
            'floor' => $this->floor,
            'postal_code' => $this->postalCode,
            'city' => $this->city,
            'country' => $this->country,
            'phone_number' => $this->phoneNumber,
            'email' => $this->email,
            'bank_account_number' => $this->bankAccountNumber,
            'bank_code' => $this->bankCode,
            'additional_bank_account_number' => $this->additionalBankAccountNumber,
            'address_type' => $this->addressType,
            'external_id' => $this->externalId,
            '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,
            'inpost_default_point' => $this->inpostDefaultPoint,
            'dhl_default_point' => $this->dhlDefaultPoint,
            'orlen_default_point' => $this->orlenDefaultPoint,
            'poczta_polska_default_point' => $this->pocztaPolskaDefaultPoint,
            'dpd_default_point' => $this->dpdDefaultPoint,
            'ups_default_point' => $this->upsDefaultPoint,
            'balikovna_default_point' => $this->balikovnaDefaultPoint,
            'gls_default_point' => $this->glsDefaultPoint,
            'ppl_default_point' => $this->pplDefaultPoint,
            'zasilkovna_default_point' => $this->zasilkovnaDefaultPoint,
            'sameday_default_point' => $this->samedayDefaultPoint,
            'fan_courier_default_point' => $this->fanCourierDefaultPoint,
            'cargus_default_point' => $this->cargusDefaultPoint,
            'pickup_hour_from' => $this->pickupHourFrom,
            'pickup_hour_to' => $this->pickupHourTo,
            'auto_complete_content_for_order_id' => $this->autoCompleteContentForOrderId,
            'auto_declared_value' => $this->autoDeclaredValue,
            'sameday_dispatch' => $this->samedayDispatch,
        ];
    }
}