<?php

namespace Opencart\Extension\Alsendo\DTO\Entity;

class AlsendoShipmentStatusEntity
{
    public int $id;
    public string $name;
    public int $order;
    public ?int $regionId;
    public array $data;
    public ?int $orderStatusId;
    public ?array $mappedOrderStatus = null;
    public static function fromArray(array $data): self
    {
        $self = new self();

        $self->id = $data['id'];
        $self->name = $data['name'];
        $self->order = $data['order'];
        $self->regionId = $data['region_id'] ?? null;
        $self->orderStatusId = $data['order_status_id'] ?? null;

        $jsonData = $data['data'] ?? [];
        if (is_string($jsonData) && !empty($jsonData)) {
            $jsonData = json_decode($jsonData, true);
        }
        $self->data = $jsonData;

        return $self;
    }

    public function setMappedOrderStatus(?array $mappedOrderStatus): void {
        $this->mappedOrderStatus = $mappedOrderStatus;
    }

    public function getMappedOrderStatus(): ?array {
        return $this->mappedOrderStatus;
    }
}