; ============================================================================
; Module Declarations for SelfHost Blog Engine
; ============================================================================

DeclareModule General
	; -- Public structures --
	Structure BlueSkyData
		Handle.s
		Password.s
		Session.BlueskyAPI::Session
		Enabled.b
		Message.s
	EndStructure
	
	; -- configuration --
	#LanguageCount = 2
	; setup bluesky integration
	Global Dim BlueSky.BlueSkyData(#LanguageCount -1)
	BlueSky(0)\Message= "New blog article: SH:TITLE"+#CRLF$+"Read it there: SH:URL"
	BlueSky(1)\Message= "Nouvel article sur le blog : SH:TITLE"+#CRLF$+"Lisez le là : SH:URL"
	
	CompilerIf #PB_Compiler_Debugger
		#Address = "http://127.0.0.1/"
	CompilerElse
		#Address = "https://lastlife.net/"
	CompilerEndIf
	#FCGIPort = 5600
	
	; -- Secrets --
	CompilerIf #PB_Compiler_Debugger = #False
		;When compiling for production, create a secrets.pbi file in the includes folder, and add all you real app secrets there.
		IncludeFile "secrets.pbi"
	CompilerElse
		#SecretKey = "ChangeThisKeyBeforeBuildingForTheRealWorld"

		; Post in english
		BlueSky(0)\Handle = "lastlife.bsky.social"
		;BlueSky(0)\Password = "xxxx-xxxx-xxxx-xxxx"
		
		; Post in french
		BlueSky(1)\Handle = "lastlifefr.bsky.social"
		;BlueSky(1)\Password = "xxxx-xxxx-xxxx-xxxx"
		
		; Contact form :
		#Email = "youremail@gmail.com"
		#PassWord = "yourpassword"
		
	CompilerEndIf
	
	; -- Public Procedures --
	Declare Init()
EndDeclareModule

DeclareModule DataModel
	; -- Public structures --
	Structure File
		*data
		size.q
		mime.s
		ID.l
	EndStructure
	
	Structure ArticleFile
		*data
		size.q
	EndStructure
	
	Structure Article
		language.ArticleFile[General::#LanguageCount]
		ID.l
		Draft.b
		Tags.i
		Date.i
	EndStructure
	
	Structure StructurePage
		language.ArticleFile[General::#LanguageCount]
	EndStructure
	
	Structure Tag
		ID.l
		DefaultName.s
		Name.s[General::#LanguageCount]
		Color.s
		BinaryID.i  ; Power of 2 for bitfield storage
	EndStructure
	
	; -- Public variables --
	Global *PreviewData = AllocateMemory(1)
	Global PreviewSize = 1
	Global PreviewUUID.s
	
	; -- Data Collections --
	Global NewList Tags.Tag()
	Global NewMap Language()
	Global NewMap MIMETypes.s()
	Global NewMap Binaries.File(2048)
	Global NewMap AdminBinaries.File(512)
	Global NewMap Articles.Article(512)
	Global NewMap StructurePages.StructurePage(256)
	
	; -- Public Procedures --
	Declare Init()
	Declare.s MakeUUID()
	
	Declare.s CreateArticle()
	Declare.s GetArticle(ID)
	Declare.s ListArticles()
	Declare UpdateArticle(TextBundle.s)
	Declare.s PreviewArticle(TextBundle.s)
	Declare DeleteArticle(ID)
	
	Declare.s ListFiles()
	Declare.s NewFile(Name.s, Base64File.s)
	Declare DeleteAFile(ID)
	
	Declare.s ListTags()
	Declare.s CreateTag()
	Declare.s GetTag(ID)
	Declare UpdateTag(TextBundle.s)
	
	Declare.s ListLanguages()
EndDeclareModule

DeclareModule FCGI	
	; -- Public Procedures --
	Declare Init()
	Declare MainLoop()
EndDeclareModule
; IDE Options = PureBasic 6.30 beta 5 (Linux - x64)
; CursorPosition = 22
; FirstLine = 2
; Folding = 4
; EnableXP
; DPIAware