const std = @import("std"); const json_utils = @import("../json_utils.zig"); const Store = @import("../store.zig"); const json = std.json; const ItemQuantity = @This(); id: Store.CodeId, quantity: u64, pub fn init(id: Store.CodeId, quantity: u64) ItemQuantity { return ItemQuantity{ .id = id, .quantity = quantity }; } pub fn parse(store: *Store, slot_obj: json.ObjectMap) !?ItemQuantity { const code = try json_utils.getStringRequired(slot_obj, "code"); if (code.len == 0) return null; const quantity = try json_utils.getIntegerRequired(slot_obj, "quantity"); if (quantity < 0) return error.InvalidQuantity; return ItemQuantity{ .id = try store.getCodeId(code), .quantity = @intCast(quantity), }; }