import Foundation

public enum TransferEncoding: String, Sendable {
	case base64
	case quotedPrintable = "quoted-printable"
	case sevenBit = "7bit"
	case eightBit = "8bit"
	case binary
}

public enum ContentDisposition: Sendable {
	case inline
	case attachment
}

public struct MIMEPart: Sendable {
	public var headers: [String: String]
	public var contentType: String
	public var charset: String?
	public var transferEncoding: TransferEncoding
	public var disposition: ContentDisposition?
	public var filename: String?
	public var contentId: String?
	public var body: Data
	public var subparts: [MIMEPart]

	public init(
		headers: [String: String] = [:],
		contentType: String = "text/plain",
		charset: String? = "utf-8",
		transferEncoding: TransferEncoding = .sevenBit,
		disposition: ContentDisposition? = nil,
		filename: String? = nil,
		contentId: String? = nil,
		body: Data = Data(),
		subparts: [MIMEPart] = []
	) {
		self.headers = headers
		self.contentType = contentType
		self.charset = charset
		self.transferEncoding = transferEncoding
		self.disposition = disposition
		self.filename = filename
		self.contentId = contentId
		self.body = body
		self.subparts = subparts
	}
}

public struct MIMEAttachment: Sendable {
	public var filename: String
	public var mimeType: String
	public var size: Int
	public var contentId: String?
	public var sectionPath: String
	public var isInline: Bool

	public init(
		filename: String,
		mimeType: String,
		size: Int,
		contentId: String? = nil,
		sectionPath: String,
		isInline: Bool = false
	) {
		self.filename = filename
		self.mimeType = mimeType
		self.size = size
		self.contentId = contentId
		self.sectionPath = sectionPath
		self.isInline = isInline
	}
}

public struct MIMEMessage: Sendable {
	public var headers: [String: String]
	public var parts: [MIMEPart]
	public var textBody: String?
	public var htmlBody: String?
	public var attachments: [MIMEAttachment]
	public var inlineImages: [MIMEAttachment]

	public init(
		headers: [String: String] = [:],
		parts: [MIMEPart] = [],
		textBody: String? = nil,
		htmlBody: String? = nil,
		attachments: [MIMEAttachment] = [],
		inlineImages: [MIMEAttachment] = []
	) {
		self.headers = headers
		self.parts = parts
		self.textBody = textBody
		self.htmlBody = htmlBody
		self.attachments = attachments
		self.inlineImages = inlineImages
	}
}
