package crm

import (
	"context"

	"apps/backend/internal/logic/crmmap"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *SetContactFollowUpLogic) SetContactFollowUp(req *types.SetContactFollowUpReq) (*types.ContactPublic, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	c, err := l.svcCtx.Crm.SetFollowUp(l.ctx, uid, req.Id, req.NeedsFollowUp, req.Days)
	if err != nil {
		return nil, err
	}
	return crmmap.Contact(c), nil
}
