// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package brand

import (
	"context"

	domusecase "haixun-backend/internal/model/brand/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *UpdateBrandProductLogic) UpdateBrandProduct(req *types.UpdateBrandProductHandlerReq) (resp *types.BrandProductData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	item, err := l.svcCtx.Brand.UpdateProduct(l.ctx, domusecase.UpdateProductRequest{
		TenantID:       tenantID,
		OwnerUID:       uid,
		BrandID:        req.ID,
		ProductID:      req.ProductID,
		Label:          req.Label,
		ProductContext: req.ProductContext,
		MatchTags:      req.MatchTags,
		MatchTagsSet:   req.MatchTags != nil,
	})
	if err != nil {
		return nil, err
	}
	out := toBrandProductData(*item)
	return &out, nil
}
