--- @class Embed
--- @field Title string
--- @field Description string
--- @field URL string
--- @field Color number
--- @field Footer EmbedFooter
--- @field Author EmbedAuthor
--- @field Fields table
local EMBED = {}
EMBED.__index = EMBED

function EMBED:__new()
	self.Title = ""
	self.Description = ""
	self.URL = ""
	self.Color = 0
	self.Footer = oop.CreateNew("EmbedFooter")
	self.Author = oop.CreateNew("EmbedAuthor")
	self.Fields = {}
end

function EMBED:__json()
	local SelfParse = {
		title = self.Title,
		description = self.Description,
		url = self.URL,
		color = self.Color,
		fields = {}
	}

	SelfParse.footer = self.Footer:__json()
	SelfParse.author = self.Author:__json()

	for i = 1, #self.Fields do
		table.insert(SelfParse.fields, self.Fields[i]:__json())
	end

	return SelfParse
end

--- Sets Embed title
--- @param Title string Title content, will fail to send if >256 characters
--- @return Embed self
function EMBED:WithTitle(Title)
	self.Title = Title
	return self
end

--- Sets Embed description
--- @param Description string Description content, will fail to send if >4096 characters
--- @return Embed self
function EMBED:WithDescription(Description)
	self.Description = Description
	return self
end

--- Sets Embed color
--- @param Color Color
--- @return Embed self
function EMBED:WithColor(Color)
	self.Color = colors.ToDecimal(Color)
	return self
end

--- Sets Embed color
--- @param R number
--- @param G number
--- @param B number
--- @return Embed self
function EMBED:WithColorRGB(R, G, B)
	self.Color = colors.ToDecimalRGB(R, G, B)
	return self
end

--- Begins EmbedFooter
--- @return EmbedFooter Footer
function EMBED:WithFooter()
	self.Footer.Embed = self

	return self.Footer
end

--- Begins EmbedAuthor
--- @return EmbedAuthor Author
function EMBED:WithAuthor()
	self.Author.Embed = self

	return self.Author
end

--- Begins EmbedField
--- @return EmbedField Field
function EMBED:WithField()
	local Field = oop.CreateNew("EmbedField")
	Field.Embed = self

	table.insert(self.Fields, Field)

	return Field
end

--- Ends an embed builder, adds it to its parent, and returns to the Message stack
--- @return Message Parent
function EMBED:End()
	local Message = self.Message
	self.Message = nil

	table.insert(Message.Embeds, self)

	return Message
end

return EMBED
