package routes

import (
	"github.com/gofiber/fiber/v2"

	apphandler "github.com/break/junhong_cmp_fiber/internal/handler/app"
	"github.com/break/junhong_cmp_fiber/internal/model/dto"
	"github.com/break/junhong_cmp_fiber/pkg/openapi"
)

// registerPersonalNotificationRoutes 注册当前个人客户的简化站内通知路由。
func registerPersonalNotificationRoutes(router fiber.Router, handler *apphandler.ClientNotificationHandler, doc *openapi.Generator, basePath string) {
	notifications := router.Group("/notifications")
	groupPath := basePath + "/notifications"

	Register(notifications, doc, groupPath, "GET", "/unread-count", handler.UnreadCount, RouteSpec{
		Summary:     "查询个人客户通知未读数",
		Description: "仅查询当前认证个人客户的未过期业务通知，平台同步和系统运维通知不会进入结果。",
		Tags:        []string{"个人客户 - 站内通知"},
		Output:      new(dto.NotificationUnreadCountResponse),
		Auth:        true,
	})

	Register(notifications, doc, groupPath, "GET", "", handler.List, RouteSpec{
		Summary:     "查询个人客户通知列表",
		Description: "仅返回当前认证个人客户的未过期业务通知，可按已读状态筛选，固定按创建时间和通知 ID 倒序。当前 C 端契约只承诺列表展示和未读弹窗；ref_type/ref_id/ref_key 是资源引用与展示快照，不是URL，也不承诺可直接拼接页面路由。",
		Tags:        []string{"个人客户 - 站内通知"},
		Input:       new(dto.PersonalNotificationListRequest),
		Output:      new(dto.PersonalNotificationListResponse),
		Auth:        true,
	})

	// 静态路径必须先于通知 ID 动态路径，避免被动态参数吞掉。
	Register(notifications, doc, groupPath, "PUT", "/read-all", handler.MarkAllRead, RouteSpec{
		Summary:     "全部标记个人客户通知已读",
		Description: "只更新当前认证个人客户可见的未过期未读业务通知，重复调用幂等成功。",
		Tags:        []string{"个人客户 - 站内通知"},
		Output:      new(dto.NotificationReadAllResponse),
		Auth:        true,
	})

	Register(notifications, doc, groupPath, "PUT", "/:id/read", handler.MarkRead, RouteSpec{
		Summary:     "标记个人客户单条通知已读",
		Description: "仅更新当前认证个人客户可见的通知；通知不存在、属于别人或已经已读均幂等成功。",
		Tags:        []string{"个人客户 - 站内通知"},
		Input:       new(dto.NotificationIDParams),
		Output:      new(dto.NotificationReadResponse),
		Auth:        true,
	})
}
