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

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

const B64Decoder = std.base64.standard.Decoder;

pub fn onGetMail(session: *Session, _: *const Packet, allocator: Allocator) !void {
    var rsp = protocol.GetMailScRsp.init(allocator);
    var item_attachment = ArrayList(protocol.Item).init(allocator);
    try item_attachment.appendSlice(&[_]protocol.Item{
        .{ .ItemId = 1407, .Num = 1 },
    });
    var mail = protocol.ClientMail.init(allocator);
    mail.Sender = .{ .Const = "Castorice" };
    mail.Title = .{ .Const = "Readme" };
    mail.IsRead = false;
    mail.id = 1;
    mail.Content = .{ .Const = "CastoriceSR is a free and open-source sofware\nJoin our discord: https://discord.gg/reversedrooms\nUse https://yunlisr-relic-builder.vercel.app to setup relic :Đ\n" };
    mail.Time = 1723334400;
    mail.ExpireTime = 17186330890;
    mail.MailType = protocol.MailType.MAIL_TYPE_STAR;
    mail.Attachment = .{ .ItemList_ = item_attachment };

    var mail_list = ArrayList(protocol.ClientMail).init(allocator);
    try mail_list.append(mail);

    rsp.TotalNum = 1;
    rsp.IsEnd = true;
    rsp.Start = 0;
    rsp.retcode = 0;
    rsp.MailList = mail_list;

    try session.send(CmdID.CmdGetMailScRsp, rsp);
}
