//
//  DisplayData.swift
//  SiiLibSample
//

import Foundation

/// Data used in display samples
struct DisplayData {
    var total: Int
    var paid: Int
    var change: Int
    var itemIndex: Int
    var itemName: String
    var itemPrice: Int
    
    private let ITEMNAMES_EN: [String] = [
        "BROCCOLI 0.808kg",
        "BANANA 0.442kg",
        "POTATO 1.328kg",
        "GRAPES 1.174kg",
        "PEAS 0.218kg"
    ]
    private let ITEMNAMES_JA: [String] = [
        "ブロッコリー ",
        "バナナ ",
        "ポテト ",
        "ブドウ ",
        "エンドウマメ "
    ]
    private let ITEMPRICES: [Int] = [132, 186, 391, 116, 100]
    
    init() {
        self.total = 0
        self.paid = 0
        self.change = 0
        self.itemIndex = 0
        self.itemName = ""
        self.itemPrice = 0
    }
    
    mutating func pickAnItem(lang: String) {
        itemName = lang.hasPrefix("ja") ? ITEMNAMES_JA[itemIndex] : ITEMNAMES_EN[itemIndex]
        itemPrice = ITEMPRICES[itemIndex]
        itemIndex = (itemIndex + 1) % 5
        total += itemPrice
    }
    
    mutating func calculateTotal() {
        paid = ((total + 999) / 1000) * 1000
        change = paid - total
    }
}
