package radar

import (
	"context"

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

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

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

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

func (l *AcceptOpportunityLogic) AcceptOpportunity(req *types.AcceptOpportunityReq) (*types.AcceptOpportunityData, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	o, contactID, err := l.svcCtx.Radar.AcceptOpportunity(l.ctx, uid, req.Id)
	if err != nil {
		return nil, err
	}
	return &types.AcceptOpportunityData{OpportunityId: o.ID, ContactId: contactID, Status: o.Status}, nil
}
