<?php

namespace apexl\Io\modules\subscription\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\subscription\entities\subscriptionEntity') {
            $fields['subscription'] = ['subscription.date_starts, subscription.enabled, subscription.product_id'];
        }

        return $fields;
    }

    public static function loadQuery($query, $table, $extends)
    {

        if (isset($extends->entity) && isset($extends->foreignKey) && $extends->entity == 'apexl\Io\modules\subscription\entities\subscriptionEntity') {
            $query->join('subscription', 'subscription.id', $table.'.'.$extends->foreignKey);
        }

        return $query;
    }

}