{"size": 1446, "ext": "js", "max_stars_repo_path": "Contributors/TheMob/2022/05_May/11May/cashRegister.js", "max_stars_repo_name": "MartinRosenberg/Coders-Workshop", "max_stars_repo_stars_event_min_datetime": "2019-01-13T22:32:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-14T03:17:52.000Z", "max_issues_repo_path": "Contributors/TheMob/2022/05_May/11May/cashRegister.js", "max_issues_repo_name": "MartinRosenberg/Coders-Workshop", "max_issues_repo_issues_event_min_datetime": "2019-01-31T18:39:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-17T01:10:55.000Z", "max_forks_repo_path": "Contributors/TheMob/2022/05_May/11May/cashRegister.js", "max_forks_repo_name": "MartinRosenberg/Coders-Workshop", "max_forks_repo_forks_event_min_datetime": "2019-02-10T22:04:29.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-21T01:14:41.000Z"}
{"max_stars_count": 13, "max_issues_count": 21, "max_forks_count": 25, "avg_line_length": 25.3684210526, "max_line_length": 86, "alphanum_fraction": 0.6542185339}

// create a cash register

// what are the inputs and outputs that are expected?
// should have methods add (makeSale), subtract(refund) abstract tax away (setTaxRate)
// total amount in register
// inventory, balance, log

class CashRegister {
	constructor(initialMoney = 100) {
        this.balance = initialMoney
        this.inventory ={}
        this.log=[]
		this.taxRate = 0
	}
	// set tax rate, initialize balance, get balance
	setTaxRate(rate) {
		this.taxRate = rate
	}
	
	initializeBalance(balance) {
		this.balance = balance
	}

	getBalance() {
		return this.balance
	}
	makeSale(name, price) {
        if(!this.inventory[name]){
            this.inventory[name]=1
        } else {
            this.inventory[name]++
        }
        price = price + (price*this.taxRate)
        this.balance += price
        let id = this.log.length
        this.log.push({ name, price, id })
	}

	refund(id) {
		// look up in log, get name, reduce inventory, get amount, do reverse of makeSale
        let { name, id: originalId, price } = this.log[id]
		this.balance -= price
		this.inventory[name]--
        let refundId = this.log.length
        this.log.push({ name, price, id: refundId, referenceId: originalId })
	}

}

const codersRegister = new CashRegister(1337);
codersRegister.setTaxRate(0.07)
codersRegister.makeSale('computer', 1000)
codersRegister.makeSale('tacos', 2000)
codersRegister.makeSale('lamp', 10)
codersRegister.refund(2)
