package http

import (
	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/blockedemail"
	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/collection"
	commonhttp "codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/common"
	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/dashboard"
	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/file"
	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/inviteemail"
	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/me"
	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/tag"
	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/user"
)

// Handlers aggregates all HTTP handlers
type Handlers struct {
	// Common handlers
	Version *commonhttp.MapleFileVersionHTTPHandler

	// Dashboard handlers
	GetDashboard *dashboard.GetDashboardHTTPHandler

	// Me handlers
	GetMe              *me.GetMeHTTPHandler
	UpdateMe           *me.PutUpdateMeHTTPHandler
	DeleteMe           *me.DeleteMeHTTPHandler
	ChangeEmailRequest *me.PostChangeEmailRequestHTTPHandler
	ChangeEmailVerify  *me.PostChangeEmailVerifyHTTPHandler

	// User handlers
	UserPublicLookup *user.UserPublicLookupHTTPHandler

	// Blocked Email handlers
	CreateBlockedEmail *blockedemail.CreateBlockedEmailHTTPHandler
	ListBlockedEmails  *blockedemail.ListBlockedEmailsHTTPHandler
	DeleteBlockedEmail *blockedemail.DeleteBlockedEmailHTTPHandler

	// Invite Email handlers
	SendInviteEmail *inviteemail.SendInviteEmailHTTPHandler

	// Collection handlers - Basic CRUD
	CreateCollection     *collection.CreateCollectionHTTPHandler
	GetCollection        *collection.GetCollectionHTTPHandler
	ListUserCollections  *collection.ListUserCollectionsHTTPHandler
	UpdateCollection     *collection.UpdateCollectionHTTPHandler
	SoftDeleteCollection *collection.SoftDeleteCollectionHTTPHandler
	ArchiveCollection    *collection.ArchiveCollectionHTTPHandler
	RestoreCollection    *collection.RestoreCollectionHTTPHandler

	// Collection handlers - Hierarchical operations
	FindCollectionsByParent *collection.FindCollectionsByParentHTTPHandler
	FindRootCollections     *collection.FindRootCollectionsHTTPHandler
	MoveCollection          *collection.MoveCollectionHTTPHandler

	// Collection handlers - Sharing
	ShareCollection       *collection.ShareCollectionHTTPHandler
	RemoveMember          *collection.RemoveMemberHTTPHandler
	ListSharedCollections *collection.ListSharedCollectionsHTTPHandler

	// Collection handlers - Filtered operations
	GetFilteredCollections *collection.GetFilteredCollectionsHTTPHandler

	// Collection Sync
	CollectionSync *collection.CollectionSyncHTTPHandler

	// File handlers - Basic CRUD
	SoftDeleteFile                *file.SoftDeleteFileHTTPHandler
	DeleteMultipleFiles           *file.DeleteMultipleFilesHTTPHandler
	GetFile                       *file.GetFileHTTPHandler
	ListFilesByCollection         *file.ListFilesByCollectionHTTPHandler
	UpdateFile                    *file.UpdateFileHTTPHandler
	CreatePendingFile             *file.CreatePendingFileHTTPHandler
	CompleteFileUpload            *file.CompleteFileUploadHTTPHandler
	GetPresignedUploadURL         *file.GetPresignedUploadURLHTTPHandler
	GetPresignedDownloadURL       *file.GetPresignedDownloadURLHTTPHandler
	ReportDownloadCompleted       *file.ReportDownloadCompletedHTTPHandler
	ArchiveFile                   *file.ArchiveFileHTTPHandler
	RestoreFile                   *file.RestoreFileHTTPHandler
	ListRecentFiles               *file.ListRecentFilesHTTPHandler

	// File Sync
	FileSync *file.FileSyncHTTPHandler

	// Tag handlers
	CreateTag               *tag.CreateTagHTTPHandler
	ListTags                *tag.ListTagsHTTPHandler
	GetTag                  *tag.GetTagHTTPHandler
	UpdateTag               *tag.UpdateTagHTTPHandler
	DeleteTag               *tag.DeleteTagHTTPHandler
	AssignTag               *tag.AssignTagHTTPHandler
	UnassignTag             *tag.UnassignTagHTTPHandler
	GetTagsForCollection    *tag.GetTagsForCollectionHTTPHandler
	GetTagsForFile          *tag.GetTagsForFileHTTPHandler
	ListCollectionsByTag    *tag.ListCollectionsByTagHandler
	ListFilesByTag          *tag.ListFilesByTagHandler
	SearchByTags            *tag.SearchByTagsHandler
}

// NewHandlers creates and wires all HTTP handlers
func NewHandlers(
	// Common
	versionHandler *commonhttp.MapleFileVersionHTTPHandler,

	// Dashboard
	getDashboard *dashboard.GetDashboardHTTPHandler,

	// Me
	getMe *me.GetMeHTTPHandler,
	updateMe *me.PutUpdateMeHTTPHandler,
	deleteMe *me.DeleteMeHTTPHandler,
	changeEmailRequest *me.PostChangeEmailRequestHTTPHandler,
	changeEmailVerify *me.PostChangeEmailVerifyHTTPHandler,

	// User
	userPublicLookup *user.UserPublicLookupHTTPHandler,

	// Blocked Email
	createBlockedEmail *blockedemail.CreateBlockedEmailHTTPHandler,
	listBlockedEmails *blockedemail.ListBlockedEmailsHTTPHandler,
	deleteBlockedEmail *blockedemail.DeleteBlockedEmailHTTPHandler,

	// Invite Email
	sendInviteEmail *inviteemail.SendInviteEmailHTTPHandler,

	// Collection - Basic CRUD
	createCollection *collection.CreateCollectionHTTPHandler,
	getCollection *collection.GetCollectionHTTPHandler,
	listUserCollections *collection.ListUserCollectionsHTTPHandler,
	updateCollection *collection.UpdateCollectionHTTPHandler,
	softDeleteCollection *collection.SoftDeleteCollectionHTTPHandler,
	archiveCollection *collection.ArchiveCollectionHTTPHandler,
	restoreCollection *collection.RestoreCollectionHTTPHandler,

	// Collection - Hierarchical
	findCollectionsByParent *collection.FindCollectionsByParentHTTPHandler,
	findRootCollections *collection.FindRootCollectionsHTTPHandler,
	moveCollection *collection.MoveCollectionHTTPHandler,

	// Collection - Sharing
	shareCollection *collection.ShareCollectionHTTPHandler,
	removeMember *collection.RemoveMemberHTTPHandler,
	listSharedCollections *collection.ListSharedCollectionsHTTPHandler,

	// Collection - Filtered
	getFilteredCollections *collection.GetFilteredCollectionsHTTPHandler,

	// Collection - Sync
	collectionSync *collection.CollectionSyncHTTPHandler,

	// File - CRUD
	softDeleteFile *file.SoftDeleteFileHTTPHandler,
	deleteMultipleFiles *file.DeleteMultipleFilesHTTPHandler,
	getFile *file.GetFileHTTPHandler,
	listFilesByCollection *file.ListFilesByCollectionHTTPHandler,
	updateFile *file.UpdateFileHTTPHandler,
	createPendingFile *file.CreatePendingFileHTTPHandler,
	completeFileUpload *file.CompleteFileUploadHTTPHandler,
	getPresignedUploadURL *file.GetPresignedUploadURLHTTPHandler,
	getPresignedDownloadURL *file.GetPresignedDownloadURLHTTPHandler,
	reportDownloadCompleted *file.ReportDownloadCompletedHTTPHandler,
	archiveFile *file.ArchiveFileHTTPHandler,
	restoreFile *file.RestoreFileHTTPHandler,
	listRecentFiles *file.ListRecentFilesHTTPHandler,

	// File - Sync
	fileSync *file.FileSyncHTTPHandler,

	// Tag handlers
	createTag *tag.CreateTagHTTPHandler,
	listTags *tag.ListTagsHTTPHandler,
	getTag *tag.GetTagHTTPHandler,
	updateTag *tag.UpdateTagHTTPHandler,
	deleteTag *tag.DeleteTagHTTPHandler,
	assignTag *tag.AssignTagHTTPHandler,
	unassignTag *tag.UnassignTagHTTPHandler,
	getTagsForCollection *tag.GetTagsForCollectionHTTPHandler,
	getTagsForFile *tag.GetTagsForFileHTTPHandler,
	listCollectionsByTag *tag.ListCollectionsByTagHandler,
	listFilesByTag *tag.ListFilesByTagHandler,
	searchByTags *tag.SearchByTagsHandler,
) *Handlers {
	return &Handlers{
		// Common
		Version: versionHandler,

		// Dashboard
		GetDashboard: getDashboard,

		// Me
		GetMe:              getMe,
		UpdateMe:           updateMe,
		DeleteMe:           deleteMe,
		ChangeEmailRequest: changeEmailRequest,
		ChangeEmailVerify:  changeEmailVerify,

		// User
		UserPublicLookup: userPublicLookup,

		// Blocked Email
		CreateBlockedEmail: createBlockedEmail,
		ListBlockedEmails:  listBlockedEmails,
		DeleteBlockedEmail: deleteBlockedEmail,

		// Invite Email
		SendInviteEmail: sendInviteEmail,

		// Collection - Basic CRUD
		CreateCollection:     createCollection,
		GetCollection:        getCollection,
		ListUserCollections:  listUserCollections,
		UpdateCollection:     updateCollection,
		SoftDeleteCollection: softDeleteCollection,
		ArchiveCollection:    archiveCollection,
		RestoreCollection:    restoreCollection,

		// Collection - Hierarchical
		FindCollectionsByParent: findCollectionsByParent,
		FindRootCollections:     findRootCollections,
		MoveCollection:          moveCollection,

		// Collection - Sharing
		ShareCollection:       shareCollection,
		RemoveMember:          removeMember,
		ListSharedCollections: listSharedCollections,

		// Collection - Filtered
		GetFilteredCollections: getFilteredCollections,

		// Collection Sync
		CollectionSync: collectionSync,

		// File - CRUD
		SoftDeleteFile:           softDeleteFile,
		DeleteMultipleFiles:      deleteMultipleFiles,
		GetFile:                  getFile,
		ListFilesByCollection:    listFilesByCollection,
		UpdateFile:               updateFile,
		CreatePendingFile:        createPendingFile,
		CompleteFileUpload:       completeFileUpload,
		GetPresignedUploadURL:    getPresignedUploadURL,
		GetPresignedDownloadURL:  getPresignedDownloadURL,
		ReportDownloadCompleted:  reportDownloadCompleted,
		ArchiveFile:              archiveFile,
		RestoreFile:              restoreFile,
		ListRecentFiles:          listRecentFiles,

		// File Sync
		FileSync: fileSync,

		// Tag handlers
		CreateTag:               createTag,
		ListTags:                listTags,
		GetTag:                  getTag,
		UpdateTag:               updateTag,
		DeleteTag:               deleteTag,
		AssignTag:               assignTag,
		UnassignTag:             unassignTag,
		GetTagsForCollection:    getTagsForCollection,
		GetTagsForFile:          getTagsForFile,
		ListCollectionsByTag:    listCollectionsByTag,
		ListFilesByTag:          listFilesByTag,
		SearchByTags:            searchByTags,
	}
}
