package crm

import (
	"context"

	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

// DeleteContact removes the contact from the working list while retaining
// opportunity, touch, and conversion history for audit and attribution.
func (l *DeleteContactLogic) DeleteContact(req *types.ContactIdReq) (*types.OkData, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	if err := l.svcCtx.Crm.RemoveContact(l.ctx, uid, req.Id); err != nil {
		return nil, err
	}
	return &types.OkData{Ok: true, Message: "contact removed from list"}, nil
}
