<?php
/**
 * Category Handler – business logic to fetch categories via the Category Service.
 *
 * @package    MOMCS_Sync
 * @subpackage MOMCS_Sync\includes\common\handlers
 * @author     miniOrange
 */

declare(strict_types=1);

namespace MOMCS_Sync\Includes\Common\Handlers;

use MOMCS_Sync\Includes\Common\Services\Amazon\Category_Service;
use WP_Error;

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

/**
 * Class Category_Handler
 */
class Category_Handler {
	/**
	 * Fetch categories for a given channel and marketplace.
	 *
	 * @param string $channel_uuid    Channel UUID.
	 * @param string $marketplace_id  Amazon marketplace ID.
	 *
	 * @return array|WP_Error
	 */
	public function fetch_categories( string $channel_uuid, string $marketplace_id ) {
		try {
			$service = new Category_Service();
			return $service->get_categories( $channel_uuid, $marketplace_id );
		} catch ( \Throwable $e ) {
			return new WP_Error( 'momcs_sync_category_error', 'Failed to fetch categories.' );
		}
	}
}
