<?php

namespace Modules\LandedCost\Entities\Drivers;

class LandedCostDriverFactory
{
    /**
     * Resolve a driver for a polymorphic parent.
     *
     * @param  string  $parentType  'pr_share' | 'purchase' | 'purchase_order'
     * @param  mixed   $parentRef   share_token for pr_share, transaction id for core
     */
    public static function make(string $parentType, $parentRef): LandedCostDriverInterface
    {
        switch ($parentType) {
            case 'pr_share':
                return new PrShareDriver($parentRef);
            case 'purchase':
                return new CoreTransactionDriver($parentRef, 'purchase');
            case 'purchase_order':
                return new CoreTransactionDriver($parentRef, 'purchase_order');
            default:
                abort(404);
        }
    }

    /** Parent types this module knows how to handle. */
    public static function supportedTypes(): array
    {
        return ['pr_share', 'purchase', 'purchase_order'];
    }
}
