using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PSO2SERVER.Models
{
    public struct MailId
    {
        /// Mail ID.
        public uint MailIdValue;
        public uint Unk1;
        public uint Unk2;

        // Constructor for easier initialization
        public MailId(uint mailId, uint unk1, uint unk2)
        {
            MailIdValue = mailId;
            Unk1 = unk1;
            Unk2 = unk2;
        }
    }

    public unsafe struct MailHeader
    {
        /// Mail ID.
        public uint MailIdValue;
        public uint Unk2;
        /// Sender player ID (?).
        public uint UserId;
        public fixed byte Unk3[0x14]; // byte[0x14]
        public uint Unk4;
        public uint Unk5;
        /// Mail receive timestamp.
        public TimeSpan ReceiveTime;
        public uint Unk6;
        /// Sender name (0x22 length).
        public string Sender;
        /// Mail subject (0x2A length).
        public string Subject;

        // Constructor for easier initialization
        public MailHeader(uint mailId, uint unk2, uint userId, byte[] unk3, uint unk4, uint unk5, TimeSpan receiveTime, uint unk6, string sender, string subject)
        {
            MailIdValue = mailId;
            Unk2 = unk2;
            UserId = userId;
            //Unk3 = 0;
            Unk4 = unk4;
            Unk5 = unk5;
            ReceiveTime = receiveTime;
            Unk6 = unk6;
            Sender = sender.Length > 0x22 ? sender.Substring(0, 0x22) : sender.PadRight(0x22, '\0');
            Subject = subject.Length > 0x2A ? subject.Substring(0, 0x2A) : subject.PadRight(0x2A, '\0');
        }
    }

    [Flags]
    public enum MailType : uint 
    {
        ALL = 0x00000065,
        SYSTEM = 0x0000000A,
        CHAR = 0x00000009,
        FRIENDANDGUILD = 0x00000001,
        MAILSENDED = 0x00000006
    }
}
