package teamworkflow

import (
	"github.com/gin-gonic/gin"

	"github.com/tidbcloud/AgentTeam/internal/api"
)

type Dependencies struct {
	AuthStore                 api.SessionAuthenticator
	WorkspaceStore            api.WorkspaceResolver
	EmailVerificationRequired bool
	Service                   Service
}

// RegisterRoutes mounts the creator-private Team Workflow browser surface.
// Creation remains conversational: Team Channel authoring invokes the domain
// lifecycle. This API lists, reads, archives/restores, and deletes its durable
// relations without exposing workspace-wide Plan lifecycle bypasses.
func RegisterRoutes(router gin.IRouter, dependencies Dependencies) {
	if router == nil || dependencies.Service == nil {
		return
	}
	workspaceScoped := router.Group(
		"/api/v1/workspaces/:workspaceId",
		api.RequireAuthenticatedUser(dependencies.AuthStore),
		api.RequireVerifiedIdentity(dependencies.EmailVerificationRequired),
		api.RequireRouteWorkspace(dependencies.WorkspaceStore),
	)
	handlers := newRouteHandlers(dependencies.Service)
	collectionPath := "/teams/:teamId/workflows"
	detailPath := collectionPath + "/:teamWorkflowId"
	workspaceScoped.GET(collectionPath, api.HandleWorkspaceScoped(handlers.collection.List, api.WithErrorClassifier(classifyError)))
	workspaceScoped.GET(detailPath, api.HandleWorkspaceScoped(handlers.detail.Get, api.WithErrorClassifier(classifyError)))
	workspaceScoped.POST(detailPath+"/archive", api.HandleWorkspaceScoped(handlers.archive.Update, api.WithErrorClassifier(classifyError)))
	workspaceScoped.POST(detailPath+"/restore", api.HandleWorkspaceScoped(handlers.restore.Update, api.WithErrorClassifier(classifyError)))
	workspaceScoped.DELETE(detailPath, api.HandleWorkspaceScoped(handlers.detail.Delete, api.WithErrorClassifier(classifyError)))
}
