import Card from './Card';
import {cloneDeep} from 'lodash';

export const convertDiscountFilterRowsToExportedJSONColumns = rows => convertDiscountFilterRows(rows, (offer) => {
    convertOfferRow(({type, options}) => {
    })(offer)
})
export const convertDiscountFilterRows = (rows, converter) => {
    const copyOfTheRows = cloneDeep(rows)

    copyOfTheRows.forEach(({columns}) => {
        columns.forEach(({defaultOffers, contexts}) => {
            defaultOffers.forEach(converter)

            contexts.forEach(({offers}) => {
                offers.forEach(converter)
            })
        })
    })

    return copyOfTheRows
}

export const convertOfferRow = converter => ({type, options}) => {
    if (type ===window.CouponsPlus.components.offers.Discount.type) {
        //this be a row, we need to extract its column
        converter({type, options})
    }
}

export default class Offer extends Card
{
    hasComponentToTheRight = false;

    getDescription()
    {
        throw new Error('getDescription() must be extended')
    }   

    getIconURL()
    {
        throw new Error('getIconURL() must be extended')
    }

    getExtraComponentToTheRight() 
    {
        throw new Error('getExtraComponentToTheRight() must be extended when hasComponentToTheRight = true')
    }
}