package logic

import (
	"context"
	"fmt"

	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/svc"
	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/types"
	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"

	"github.com/zeromicro/go-zero/core/logx"
)

type SurplusDetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSurplusDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SurplusDetailLogic {
	return &SurplusDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

//资源剩余详情
func (l *SurplusDetailLogic) SurplusDetail(req *types.Req) (resp *types.Reply, err error) {
	resp = &types.Reply{}
	status, total, surplus, start_time, end_time, err := Surplus(req.AppId, req.Function_code, req.Account_id, req.Ent_account_id, req.Ent_id, req.Ent_user_id)
	if err != nil {
		resp.Error_msg = err.Error()
		l.Error(fmt.Sprintf("%+v", req), err)
	}
	resp.Error_code = status
	resp.Data = &SurplusData{
		Total:      total,
		Surplus:    surplus,
		Start_time: start_time,
		End_time:   end_time,
	}
	return
}
