<?php
namespace Prodigy\Includes\Frontend\Mappers;

use Prodigy\Includes\Content\Prodigy_Brands_Parser;
use Prodigy\Includes\Models\Prodigy_Brands;

/**
 * Prodigy brands data mapper
 *
 * @version    3.1.5
 * @package    Prodigy
 * @subpackage Prodigy/includes
 */
class Prodigy_Brands_Data_Mapper extends Prodigy_Main_Data_Mapper {

	const WIDGET_TYPE = 'basic';

	/** @var Prodigy_Brands  */
	private Prodigy_Brands $brands;

	/** @var Prodigy_Brands_Parser  */
	private Prodigy_Brands_Parser $brands_parser;

	/**
	 * @param Prodigy_Brands        $brands
	 * @param Prodigy_Brands_Parser $brands_parser
	 */
	public function __construct( Prodigy_Brands $brands, Prodigy_Brands_Parser $brands_parser ) {
		parent::__construct();
		$this->brands        = $brands;
		$this->brands_parser = $brands_parser;
	}

	/**
	 * @param array $options
	 *
	 * @return array
	 * @throws \Exception
	 */
	public function get_default_parameters( array $options ): array {
		$brands = $this->request_maker->do_brands_request( 'brand-logos.logo' );

		$result = array();
		if ( ! empty( $brands['data'] ) ) {
			foreach ( $brands['data'] as $brand ) {
				$this->brands->add( $brand['attributes']['name'], $brand['attributes']['slug'] );
			}

			$data = $this->brands_parser->get_brands_data( $brands );

			$result = compact( 'data' );
		}

		return $result;
	}
}
