package logic

import (
	"context"
	"jyBXBase/rpc/bxbase"

	"jyBXBase/api/internal/svc"
	"jyBXBase/api/internal/types"

	"app.yhyue.com/moapp/jybase/common"

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

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

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

func (l *IncludedLogic) Included(req *types.IncludedReq) (resp *types.CommonRes, err error) {
	res, err0 := l.svcCtx.Bxbase.Included(l.ctx, &bxbase.AppIdReq{
		AppId: req.AppId,
	})
	if err0 != nil {
		return &types.CommonRes{
			Err_code: -1,
			Err_msg:  "错误",
			Data:     nil,
		}, nil
	}
	return &types.CommonRes{
		Err_code: common.IntAll(res.ErrorCode),
		Err_msg:  res.ErrorMsg,
		Data: map[string]interface{}{
			"year":                    res.Year,
			"month":                   res.Month,
			"day":                     res.Day,
			"bid":                     res.Bid,
			"bidUnit":                 res.BidUnit,
			"bidUnitAppend":           res.BidUnitAppend,
			"project":                 res.Project,
			"projectUnit":             res.ProjectUnit,
			"projectUnitAppend":       res.ProjectUnitAppend,
			"ent":                     res.Ent,
			"entUnit":                 res.EntUnit,
			"entUnitAppend":           res.EntUnitAppend,
			"buyer":                   res.Buyer,
			"buyerUnit":               res.BuyerUnit,
			"buyerUnitAppend":         res.BuyerUnitAppend,
			"bidDayUpdate":            res.BidDayUpdate,
			"bidDayUpdateUnit":        res.BidDayUpdateUnit,
			"bidDayUpdateUnitAppend":  res.BidDayUpdateUnitAppend,
			"bidField":                res.BidField,
			"bidFieldUnit":            res.BidFieldUnit,
			"bidFieldUnitAppend":      res.BidFieldUnitAppend,
			"fieldAccuracy":           res.FieldAccuracy,
			"fieldAccuracyUnit":       res.FieldAccuracyUnit,
			"fieldAccuracyUnitAppend": res.FieldAccuracyUnitAppend,
			"push":                    res.Push,
			"pushUnit":                res.PushUnit,
			"pushUnitAppend":          res.ProjectUnitAppend,
		},
	}, nil
	return
}
