import {PaymentResult, PaymentStrategy} from "./Payment"

export class Item {
    price: number;

    constructor(price: number) {
        this.price = price;
    }
}

export class ShoppingCart {

    private items: Item[];
    public strategy: PaymentStrategy;

    constructor(strategy: PaymentStrategy) {
        this.strategy = strategy;
        this.items = [];
    }

    AddItem(item: Item) {
        this.items.concat(item);
    }

    Pay() : PaymentResult {
        let total: number = 0
        for (let i = this.items.length - 1; i >= 0; i--) {
            total += this.items[i].price;
        }
        return this.strategy.Pay(total)
    }
}