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

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

func (l *CreateContactNoteLogic) CreateContactNote(req *types.CreateContactNoteReq) (*types.ContactTouchPublic, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	t, err := l.svcCtx.Crm.AddNote(l.ctx, uid, req.Id, req.Body)
	if err != nil {
		return nil, err
	}
	return crmmap.Touch(t), nil
}
