package Msg

import (
	"context"

	"wechat-api/internal/svc"
	"wechat-api/internal/types"
	"wechat-api/internal/utils/dberrorhandler"

    "github.com/suyuan32/simple-admin-common/msg/errormsg"

	"github.com/suyuan32/simple-admin-common/utils/pointy"
	"github.com/zeromicro/go-zero/core/logx"
)

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

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

func (l *GetMsgByIdLogic) GetMsgById(req *types.IDReq) (*types.MsgInfoResp, error) {
	data, err := l.svcCtx.DB.Msg.Get(l.ctx, req.Id)
	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}

	return &types.MsgInfoResp{
	    BaseDataInfo: types.BaseDataInfo{
            Code: 0,
            Msg:  errormsg.Success,
        },
        Data: types.MsgInfo{
            BaseIDInfo:    types.BaseIDInfo{
				Id:          &data.ID,
				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
            },
			Status:	&data.Status,
			Fromwxid:	&data.Fromwxid,
			Toid:	&data.Toid,
			Msgtype:	&data.Msgtype,
			Msg:	&data.Msg,
			BatchNo:	&data.BatchNo,
        },
	}, nil
}

