package placement_topic

import (
	"context"

	brandlogic "haixun-backend/internal/logic/brand"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *UpsertPlacementTopicScanScheduleLogic) UpsertPlacementTopicScanSchedule(req *types.UpsertPlacementTopicScanScheduleHandlerReq) (*types.BrandScanScheduleData, error) {
	if _, _, err := actorFrom(l.ctx); err != nil {
		return nil, err
	}
	return brandlogic.NewUpsertBrandScanScheduleLogic(l.ctx, l.svcCtx).UpsertBrandScanSchedule(&types.UpsertBrandScanScheduleHandlerReq{
		BrandPath: types.BrandPath{ID: req.ID},
		UpsertBrandScanScheduleReq: types.UpsertBrandScanScheduleReq{
			Cron:     req.Cron,
			Timezone: req.Timezone,
			Enabled:  req.Enabled,
		},
	})
}
