<?php
/**
 * Parser Factory.
 *
 * @package PrimeLink
 */

namespace PrimeLink\Modules\Imports\Parsers;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

final class ParserFactory {

    /**
     * Make parser instance by file type.
     *
     * @param string $type csv|xml|xlsx|json
     * @return object
     */
    public static function make( $type ) {
        $type = strtolower( (string) $type );

        switch ( $type ) {
            case 'xml':
                if ( class_exists( __NAMESPACE__ . '\\XmlParser' ) ) {
                    return new XmlParser();
                }
                break;

            case 'xlsx':
            case 'xls':
                if ( class_exists( __NAMESPACE__ . '\\XlsxParser' ) ) {
                    return new XlsxParser();
                }
                break;

            case 'json':
                if ( class_exists( __NAMESPACE__ . '\\JsonParser' ) ) {
                    return new JsonParser();
                }
                break;

            case 'csv':
            default:
                return new CsvParser();
        }

        // Fallback safe: CSV parser
        return new CsvParser();
    }
}