package service

import (
	"encoding/json"
	"github.com/go-kratos/kratos/v2/transport/http"
	v1 "voucher/api/v1"
)

func (s *VoucherService) CmbOrderMock(ctx http.Context) error {

	var req *v1.CmbOrderRequest
	if err := ctx.BindForm(&req); err != nil {
		return err
	}

	bizJsonBytes, err := json.Marshal(req)
	if err != nil {
		return err
	}

	reply, err := s.CmbMixRepo.GetMockRequest(ctx, string(bizJsonBytes))
	if err != nil {
		return err
	}

	return ctx.JSON(200, reply)
}

func (s *VoucherService) CmbProductQueryMock(ctx http.Context) error {

	var req *v1.CmbQueryProductRequest
	if err := ctx.BindForm(&req); err != nil {
		return err
	}

	bizJsonBytes, err := json.Marshal(req)
	if err != nil {
		return err
	}

	reply, err := s.CmbMixRepo.GetMockRequest(ctx, string(bizJsonBytes))
	if err != nil {
		return err
	}
	if err != nil {
		return err
	}

	return ctx.JSON(200, reply)
}
