package radar

import (
	"context"

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

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

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

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

func (l *OverrideOpportunityLogic) OverrideOpportunity(req *types.OverrideOpportunityReq) (*types.OpportunityPublic, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	o, err := l.svcCtx.Radar.OverrideOpportunity(l.ctx, uid, req.Id, req.Band, req.Status)
	if err != nil {
		return nil, err
	}
	return radarmap.Opportunity(o), nil
}
