package routes

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

	"github.com/break/junhong_cmp_fiber/internal/handler/admin"
	"github.com/break/junhong_cmp_fiber/internal/handler/callback"
	"github.com/break/junhong_cmp_fiber/internal/model/dto"
	"github.com/break/junhong_cmp_fiber/pkg/openapi"
)

// registerAdminOrderRoutes 注册后台订单路由
func registerAdminOrderRoutes(router fiber.Router, handler *admin.OrderHandler, doc *openapi.Generator, basePath string) {
	Register(router, doc, basePath, "POST", "/orders", handler.Create, RouteSpec{
		Summary: "创建订单",
		Tags:    []string{"订单管理"},
		Input:   new(dto.CreateAdminOrderRequest),
		Output:  new(dto.OrderResponse),
		Auth:    true,
	})

	Register(router, doc, basePath, "GET", "/orders", handler.List, RouteSpec{
		Summary: "获取订单列表",
		Tags:    []string{"订单管理"},
		Input:   new(dto.OrderListRequest),
		Output:  new(dto.OrderListResponse),
		Auth:    true,
	})

	Register(router, doc, basePath, "GET", "/orders/:id", handler.Get, RouteSpec{
		Summary: "获取订单详情",
		Tags:    []string{"订单管理"},
		Input:   new(dto.GetOrderRequest),
		Output:  new(dto.OrderResponse),
		Auth:    true,
	})

	Register(router, doc, basePath, "POST", "/orders/:id/cancel", handler.Cancel, RouteSpec{
		Summary: "取消订单",
		Tags:    []string{"订单管理"},
		Input:   new(dto.CancelOrderRequest),
		Output:  nil,
		Auth:    true,
	})

	Register(router, doc, basePath, "POST", "/orders/purchase-check", handler.PurchaseCheck, RouteSpec{
		Summary: "套餐购买预检",
		Tags:    []string{"订单管理"},
		Input:   new(dto.PurchaseCheckRequest),
		Output:  new(dto.PurchaseCheckResponse),
		Auth:    true,
	})
}

// registerCarrierCallbackRoutes 注册运营商业务回调路由。
func registerCarrierCallbackRoutes(router fiber.Router, handler *callback.CTCCRealnameHandler, doc *openapi.Generator, basePath string) {
	Register(router, doc, basePath, "POST", "/carriers/ctcc/realname", handler.Realname, RouteSpec{
		Summary:     "电信实名结果回调",
		Description: "接收电信 XML 实名补录结果，固定返回运营商成功应答。",
		Tags:        []string{"运营商回调"},
		Input:       nil,
		Output:      nil,
		Auth:        false,
	})
}

// registerCMCCCallbackRoutes 注册中国移动实名回调路由。
func registerCMCCCallbackRoutes(router fiber.Router, handler *callback.CMCCRealnameHandler, doc *openapi.Generator, basePath string) {
	Register(router, doc, basePath, "POST", "/carriers/cmcc/realname", handler.Realname, RouteSpec{
		Summary: "移动实名结果回调", Description: "接收中国移动 JSON 实名成功结果，固定返回运营商成功应答。",
		Tags: []string{"运营商回调"}, Input: nil, Output: nil, Auth: false,
	})
}

// registerCUCCRealnameCallbackRoutes 注册中国联通实名成功回调路由。
func registerCUCCRealnameCallbackRoutes(router fiber.Router, handler *callback.CUCCRealnameHandler, doc *openapi.Generator, basePath string) {
	Register(router, doc, basePath, "POST", "/carriers/cucc/realname", handler.Realname, RouteSpec{
		Summary: "联通实名结果回调", Description: "接收中国联通嵌套 JSON 实名成功结果，固定返回运营商成功应答。",
		Tags: []string{"运营商回调"}, Input: nil, Output: nil, Auth: false,
	})
}

// registerCUCCCallbackRoutes 注册中国联通解除实名回调路由。
func registerCUCCCallbackRoutes(router fiber.Router, handler *callback.CUCCRealnameRemovalHandler, doc *openapi.Generator, basePath string) {
	Register(router, doc, basePath, "POST", "/carriers/cucc/realname/remove", handler.Remove, RouteSpec{
		Summary: "联通解除实名回调", Description: "识别中国联通解除实名 JSON，仅留痕且不修改本地实名事实。",
		Tags: []string{"运营商回调"}, Input: nil, Output: nil, Auth: false,
	})
}

// registerPaymentCallbackRoutes 注册支付回调路由
func registerPaymentCallbackRoutes(router fiber.Router, handler *callback.PaymentHandler, doc *openapi.Generator, basePath string) {
	Register(router, doc, basePath, "POST", "/wechat-pay", handler.WechatPayCallback, RouteSpec{
		Summary: "微信支付回调",
		Tags:    []string{"支付回调"},
		Input:   nil,
		Output:  nil,
		Auth:    false,
	})

	Register(router, doc, basePath, "POST", "/alipay", handler.AlipayCallback, RouteSpec{
		Summary: "支付宝回调",
		Tags:    []string{"支付回调"},
		Input:   nil,
		Output:  nil,
		Auth:    false,
	})

	Register(router, doc, basePath, "POST", "/fuiou-pay", handler.FuiouPayCallback, RouteSpec{
		Summary: "富友支付回调",
		Tags:    []string{"支付回调"},
		Input:   nil,
		Output:  nil,
		Auth:    false,
	})
}
