package core

import (
	"context"

	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"

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

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

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

func (l *GetPublicImageLogic) GetPublicImage(req *types.PublicImageReq) (resp *types.PublicImageResp, err error) {
	// todo: add your logic here and delete this line
	resp = &types.PublicImageResp{}
	var iamgeDict []types.ImageDict
	sqlStrTask := "SELECT * FROM `vm_image_dict`"
	txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&iamgeDict)
	if txTask.Error != nil {
		logx.Error(err)
		return nil, txTask.Error
	}
	resp.Code = 200
	resp.Message = "success"
	resp.ImageDict = iamgeDict
	return resp, nil
}
