<?php

namespace Shopping\Mapping;

use Shopping\Sphinx\SphinxRow;
use Shopping\Model\ShoppingProduct;

class SphinxToCanonicalMapper {
    public function map(SphinxRow $row): ShoppingProduct {
        return new ShoppingProduct([
            // ===== REQUIRED FIELDS (always present) =====
            'sku'               => $row->get('sku') ?? '',
            'title'             => $row->get('title_string') ?? '',
            'description'       => $row->get('description_string') ?? '',
            'price'             => $row->get('price') ?? null,
            'currency'          => $row->get('currency') ?? '',
            'redirect_url'      => $row->get('redirect_url') ?? '',
            'image'             => $row->get('image_zoom') ?: ($row->get('image_small') ?? ''),
            'lastmodified'      => $row->get('lastmodified') ?? '',
            'advertiser'        => $row->get('merchant') ?? '',
            'category'          => $row->get('category') ?? '',
            'master_category'   => $row->get('master_category') ?? '',
            'brand'             => $row->get('brand') ?? '',
            'estimatedCPC'      => $row->get('expectedcpc') ?? null,

            // ===== OPTIONAL FIELDS =====
            'advertiser_domain' => $row->get('link_string') ?? null,
            'availability'      => $row->get('availability') ?? null,
            'feature'           => $row->get('feature') ?? null,
            'sale_price'        => null,
        ]);
    }
}