//
//  DisplayData.m
//  SiiLibSample
//

#import "DisplayData.h"

static NSString *const DISPLAY_ITEMNAMES_EN[] = {
    @"BROCCOLI 0.808kg",
    @"BANANA 0.442kg",
    @"POTATO 1.328kg",
    @"GRAPES 1.174kg",
    @"PEAS 0.218kg"
};
static NSString *const DISPLAY_ITEMNAMES_JA[] = {
    @"ブロッコリー ",
    @"バナナ ",
    @"ポテト ",
    @"ブドウ ",
    @"エンドウマメ "
};
static NSInteger const DISPLAY_ITEMPRICES[] = {
    132,
    186,
    391,
    116,
    100
};

/// Data used in display samples
@implementation DisplayData

- (instancetype)init {
    self = [super init];
    if (self) {
        _total = 0;
        _paid = 0;
        _change = 0;
        _itemIndex = 0;
        _itemName = @"";
        _itemPrice = 0;
    }
    return self;
}

- (void)pickAnItem: (NSString *)lang {
    _itemName = [lang hasPrefix:@"ja"] ? DISPLAY_ITEMNAMES_JA[_itemIndex] : DISPLAY_ITEMNAMES_EN[_itemIndex];
    _itemPrice = DISPLAY_ITEMPRICES[_itemIndex];
    _itemIndex = (_itemIndex + 1) % 5;
    _total += _itemPrice;
}

- (void)calculateTotal {
    _paid = ((_total + 999) / 1000) * 1000;
    _change = _paid - _total;
}
@end
