<?php

namespace apexl\Io\modules\product\callbacks;

use apexl\Io\includes\Routes;

class entityLoadCallback {

    public static function loadFields($fields, $table, $extends)
    {
        if (isset($extends->entity) && isset($extends->foreignKey) && $extends->entity = 'apexl\Io\modules\product\entities\productEntity') {
            $fields['product'] = ['product.type, product.is_default, product.product_name, product.description, product.code, product.price, product.invoice_nominal_code, product.weight_kg, product.sku, product.has_subscription'];
        }

        return $fields;
    }

    public static function loadQuery($query, $table, $extends)
    {
        if (isset($extends->entity) && isset($extends->foreignKey) && $extends->entity = 'apexl\Io\modules\product\entities\productEntity') {
            $query->join('product', 'product.id', $table.'.'.$extends->foreignKey);
        }

        return $query;
    }
}