<?php

namespace Devurai\AcceptbluePaymentPro\Order\level_2;

abstract class BaseInfo
{
    protected \WC_Order $order;

    public function __construct(\WC_Order $order)
    {
        $this->order = $order;
    }

    abstract protected function getType(): string;

    protected function getOrderFieldValue(string $field_name, string $default = '') {
        if (empty($field_name)) {
            return $default;
        }

        $type = $this->getType();
        if (empty($type)) {
            return $default;
        }

        if (!defined('WC_VERSION')) {
            return $default;
        }

        if (version_compare(constant('WC_VERSION'), '3.0.0', '<')) {
            $property_name = "${type}_${field_name}";
            return property_exists($this->order, $property_name)
                ? $this->order->$property_name
                : $default;
        } else {
            $method_name = "get_${type}_${field_name}";
            return method_exists($this->order, $method_name)
                ? $this->order->$method_name()
                : $default;
        }
    }
}