package tenant

import (
	"quyun/v2/app/http/tenant/dto"
	"quyun/v2/app/requests"
	"quyun/v2/app/services"
	"quyun/v2/database/models"

	"github.com/gofiber/fiber/v3"
	log "github.com/sirupsen/logrus"
)

// orderMe provides member order endpoints (my orders within a tenant).
//
//	@provider
type orderMe struct{}

// myOrders
//
//	@Summary	我的订单列表（当前租户）
//	@Tags		Tenant
//	@Accept		json
//	@Produce	json
//	@Param		tenantCode	path		string				true	"Tenant Code"
//	@Param		filter		query		dto.MyOrderListFilter	true	"Filter"
//	@Success	200			{object}	requests.Pager{items=models.Order}
//
//	@Router		/t/:tenantCode/v1/orders [get]
//	@Bind		tenant local key(tenant)
//	@Bind		user local key(user)
//	@Bind		filter query
func (*orderMe) myOrders(ctx fiber.Ctx, tenant *models.Tenant, user *models.User, filter *dto.MyOrderListFilter) (*requests.Pager, error) {
	log.WithFields(log.Fields{
		"tenant_id": tenant.ID,
		"user_id":   user.ID,
	}).Info("tenant.orders.me.list")

	return services.Order.MyOrderPage(ctx, tenant.ID, user.ID, filter)
}

// myOrderDetail
//
//	@Summary	我的订单详情（当前租户）
//	@Tags		Tenant
//	@Accept		json
//	@Produce	json
//	@Param		tenantCode	path		string	true	"Tenant Code"
//	@Param		orderID		path		int64	true	"OrderID"
//	@Success	200			{object}	models.Order
//
//	@Router		/t/:tenantCode/v1/orders/:orderID [get]
//	@Bind		tenant local key(tenant)
//	@Bind		user local key(user)
//	@Bind		orderID path
func (*orderMe) myOrderDetail(ctx fiber.Ctx, tenant *models.Tenant, user *models.User, orderID int64) (*models.Order, error) {
	log.WithFields(log.Fields{
		"tenant_id": tenant.ID,
		"user_id":   user.ID,
		"order_id":  orderID,
	}).Info("tenant.orders.me.detail")

	return services.Order.MyOrderDetail(ctx, tenant.ID, user.ID, orderID)
}
