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 UpdateContactStageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *UpdateContactStageLogic) UpdateContactStage(req *types.UpdateContactStageReq) (*types.ContactPublic, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	c, err := l.svcCtx.Crm.UpdateStage(l.ctx, uid, req.Id, req.Stage, req.Note)
	if err != nil {
		return nil, err
	}
	return crmmap.Contact(c), nil
}
