package banner

import (
	"context"
	"fmt"

	"sundynix-micro-go/app/plant/api/internal/svc"
	"sundynix-micro-go/app/plant/api/internal/types"
	plantModel "sundynix-micro-go/app/plant/model"

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

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

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

func (l *CreateBannerLogic) CreateBanner(req *types.CreateBannerReq) error {
	userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
	_ = userId
	banner := plantModel.Banner{
		Title:     req.Title,
		ImageID:   req.ImageId,
		Sort:      req.Sort,
		IsActive:  req.IsActive,
		TargetURL: req.TargetUrl,
	}
	if banner.IsActive == 0 {
		banner.IsActive = 1
	}
	return l.svcCtx.DB.Create(&banner).Error
}
