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

package copy_mission

import (
	"context"
	"strings"

	missiondomain "haixun-backend/internal/model/copy_mission/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *PatchCopyMissionAudienceSampleLogic) PatchCopyMissionAudienceSample(req *types.PatchAudienceSampleHandlerReq) (*types.CopyMissionData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	item, err := l.svcCtx.CopyMission.PatchAudienceSample(l.ctx, missiondomain.PatchAudienceSampleRequest{
		TenantID:  tenantID,
		OwnerUID:  uid,
		PersonaID: strings.TrimSpace(req.PersonaID),
		MissionID: strings.TrimSpace(req.ID),
		Username:  strings.TrimSpace(req.Username),
		Status:    req.Status,
	})
	if err != nil {
		return nil, err
	}
	data := toCopyMissionData(*item)
	return &data, nil
}
