package service

import (
	"context"
	"encoding/json"
	v1 "voucher/api/v1"
)

func (s *CmbService) OrderMock(ctx context.Context, request *v1.CmbOrderRequest) (*v1.CmbRequest, error) {

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

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

	return reply, nil
}

func (s *CmbService) QueryMock(ctx context.Context, request *v1.CmbQueryRequest) (*v1.CmbRequest, error) {

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

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

	return reply, nil
}

func (s *CmbService) QueryProductMock(ctx context.Context, request *v1.CmbQueryProductRequest) (*v1.CmbRequest, error) {

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

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

	return reply, nil
}

func (s *CmbService) DecryptBody(ctx context.Context, request *v1.EncryptBodyRequest) (*v1.DecryptBodyReply, error) {

	decryptBody, err := s.CmbMixRepo.Decrypt(ctx, request.EncryptBody)
	if err != nil {
		return nil, err
	}

	return &v1.DecryptBodyReply{
		DecryptBody: decryptBody,
	}, nil
}
