// zig fmt: off const std = @import("std"); const Store = @import("../store.zig"); const json_utils = @import("../json_utils.zig"); const parseDateTime = @import("../../date_time/parse.zig").parseDateTime; const EnumStringUtils = @import("../enum_string_utils.zig").EnumStringUtils; const Cooldown = @This(); pub const Reason = enum { movement, fight, crafting, gathering, buy_ge, sell_ge, cancel_ge, delete_item, deposit, withdraw, deposit_gold, withdraw_gold, equip, unequip, task, christmas_exchange, recycling, rest, use, buy_bank_expansion, const Utils = EnumStringUtils(Reason, .{ .{ "movement" , Reason.movement }, .{ "fight" , Reason.fight }, .{ "crafting" , Reason.crafting }, .{ "gathering" , Reason.gathering }, .{ "buy_ge" , Reason.buy_ge }, .{ "sell_ge" , Reason.sell_ge }, .{ "cancel_ge" , Reason.cancel_ge }, .{ "delete_item" , Reason.delete_item }, .{ "deposit" , Reason.deposit }, .{ "withdraw" , Reason.withdraw }, .{ "deposit_gold" , Reason.deposit_gold }, .{ "withdraw_gold" , Reason.withdraw_gold }, .{ "equip" , Reason.equip }, .{ "unequip" , Reason.unequip }, .{ "task" , Reason.task }, .{ "christmas_exchange", Reason.christmas_exchange }, .{ "recycling" , Reason.recycling }, .{ "rest" , Reason.rest }, .{ "use" , Reason.use }, .{ "buy_bank_expansion", Reason.buy_bank_expansion }, }); pub const fromString = Utils.fromString; pub const toString = Utils.toString; }; started_at: f64, expiration: f64, reason: Reason, pub fn parse(store: *Store, obj: std.json.ObjectMap) !Cooldown { _ = store; const started_at = try json_utils.getStringRequired(obj, "started_at"); const expiration = try json_utils.getStringRequired(obj, "expiration"); const reason = try json_utils.getStringRequired(obj, "reason"); return Cooldown{ .started_at = parseDateTime(started_at) orelse return error.InvalidStartedAt, .expiration = parseDateTime(expiration) orelse return error.InvalidExpiration, .reason = Reason.fromString(reason) orelse return error.InvalidReason }; }