const std = @import("std");
const protocol = @import("protocol");
const Session = @import("../Session.zig");
const Packet = @import("../Packet.zig");
const Config = @import("config.zig");

const ArrayList = std.ArrayList;
const Allocator = std.mem.Allocator;
const CmdID = protocol.CmdID;

pub fn onGetActivity(session: *Session, _: *const Packet, allocator: Allocator) !void {
    var rsp = protocol.GetActivityScheduleConfigScRsp.init(allocator);
    const activity_config = try Config.loadActivityConfig(allocator, "resources/ActivityConfig.json");

    for (activity_config.activity_config.items) |activityConf| {
        if (activityConf.panel_id != 30002) {
            for (activityConf.activity_module_list.items) |id| {
                var activ_list = protocol.ActivityScheduleData.init(allocator);
                activ_list.begin_time = 1664308800;
                activ_list.end_time = 4294967295;
                activ_list.activity_id = id;
                activ_list.panel_id = activityConf.panel_id;
                try rsp.schedule_data.append(activ_list);
            }
        }
    }
    rsp.retcode = 0;
    try session.send(CmdID.CmdGetActivityScheduleConfigScRsp, rsp);
}

pub fn onUpdateServerPrefsData(session: *Session, packet: *const Packet, allocator: Allocator) !void {
    var rsp = protocol.UpdateServerPrefsDataScRsp.init(allocator);
    const req = try packet.getProto(protocol.UpdateServerPrefsDataCsReq, allocator);
    rsp.server_prefs_id = req.server_prefs.?.server_prefs_id;
    rsp.retcode = 0;
    try session.send(CmdID.CmdUpdateServerPrefsDataScRsp, rsp);
}
