<?php

namespace Opencart\Admin\Model\Extension\Alsendo\Module;

require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/ServiceEntity.php');

use Opencart\Extension\Alsendo\DTO\Entity\ServiceEntity;
use Opencart\System\Engine\Model;
use Opencart\System\Engine\Registry;

class Service extends Model {
    public function __construct(Registry $registry) {
        parent::__construct($registry);
    }

    public function getServiceById(int $id): ?ServiceEntity {
        $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "alsendo_services` WHERE `id` = '" . $id . "' LIMIT 1");

        if ($query->num_rows) {
            return ServiceEntity::fromArray([
                'id' => $query->row['id'] ?? null,
                'external_id' => $query->row['external_id'] ?? '',
                'is_selected' => $query->row['is_selected'] ?? false,
                'name' => $query->row['name'] ?? '',
                'supplier' => $query->row['supplier'] ?? null,
                'to_point' => $query->row['to_point'] ?? null,
                'comment' => $query->row['comment'] ?? null,
            ]);
        }

        return null;
    }
}