artificer/api/schemas/cooldown.zig

54 lines
1.6 KiB
Zig

const std = @import("std");
const json_utils = @import("../json_utils.zig");
pub const parseDateTime = @import("../date_time/parse.zig").parseDateTime;
const EnumStringUtils = @import("../enum_string_utils.zig").EnumStringUtils;
const json = std.json;
const Cooldown = @This();
const ReasonUtils = EnumStringUtils(Reason, .{
.{ "movement" , Reason.movement },
.{ "fight" , Reason.fight },
.{ "crafting" , Reason.crafting },
.{ "gathering" , Reason.gathering },
.{ "buy_ge" , Reason.buy_ge },
.{ "sell_ge" , Reason.sell_ge },
.{ "delete_item" , Reason.delete_item },
.{ "deposit_bank" , Reason.deposit_bank },
.{ "withdraw_bank", Reason.withdraw_bank },
.{ "equip" , Reason.equip },
.{ "unequip" , Reason.unequip },
.{ "task" , Reason.task },
.{ "recycling" , Reason.recycling },
});
pub const Reason = enum {
movement,
fight,
crafting,
gathering,
buy_ge,
sell_ge,
delete_item,
deposit_bank,
withdraw_bank,
equip,
unequip,
task,
recycling,
const parse = ReasonUtils.fromString;
};
expiration: f64,
reason: Reason,
pub fn parse(obj: json.ObjectMap) !Cooldown {
const reason = try json_utils.getStringRequired(obj, "reason");
const expiration = try json_utils.getStringRequired(obj, "expiration");
return Cooldown{
.expiration = parseDateTime(expiration) orelse return error.InvalidDateTime,
.reason = Reason.parse(reason) orelse return error.UnknownReason
};
}