package xunji

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 GetXunjiByIdLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

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

func (l *GetXunjiByIdLogic) GetXunjiById(req *types.IDReq) (*types.XunjiInfoResp, error) {
	data, err := l.svcCtx.DB.Xunji.Get(l.ctx, req.Id)
	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}

	return &types.XunjiInfoResp{
	    BaseDataInfo: types.BaseDataInfo{
            Code: 0,
            Msg:  errormsg.Success,
        },
        Data: types.XunjiInfo{
            BaseIDInfo:    types.BaseIDInfo{
				Id:          &data.ID,
				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
            },
			Status:	&data.Status,
			AppKey:	&data.AppKey,
			AppSecret:	&data.AppSecret,
			Token:	&data.Token,
			EncodingKey:	&data.EncodingKey,
			AgentId:	&data.AgentID,
			OrganizationId:	&data.OrganizationID,
			Wxid:	&data.Wxid,
			ApiBase:	&data.APIBase,
			ApiKey:	&data.APIKey,
        },
	}, nil
}

