// CreatePlanCost corresponds to the POST /id/plan/:id/cost endpoint.
//
// Get plan cost
// Get how much a plan would cost when using a set of features
486886
func (c *IDClient) CreatePlanCost(ctx context.Context, id gomanifold.ID, planCostRequest *PlanCostRequest) (*Price, error) {
	idBytes, err := id.MarshalText()
	if err != nil {
		return nil, err
	}

	p := fmt.Sprintf("/id/plan/%s/cost", string(idBytes))

	req, err := c.backend.NewRequest(http.MethodPost, p, nil, planCostRequest)
	if err != nil {
		return nil, err
	}

	var resp Price
	_, err = c.backend.Do(ctx, req, &resp, func(code int) error {
		switch code {
		case 400, 404, 500:
			return &Error{}
		default:
			return nil
		}
	})
	if err != nil {
		return nil, err
	}

	return &resp, nil
}
227877
func newplanFunc(e *expr, fn GraphiteFunc, context Context, stable bool, reqs []Req) ([]Req, error) {
	// first comes the interesting task of validating the arguments as specified by the function,
	// against the arguments that were parsed.

	argsExp, _ := fn.Signature()
	var err error

	// note:
	// * signature may have seriesLists in it, which means one or more args of type seriesList
	//   so it's legal to have more e.args than signature args in that case.
	// * we can't do extensive, accurate validation of the type here because what the output from a function we depend on
	//   might be dynamically typed. e.g. movingAvg returns 1..N series depending on how many it got as input

	// first validate the mandatory args
	pos := 0    // e.args[pos]     : next given arg to process
	cutoff := 0 // argsExp[cutoff] : will be first optional arg (if any)
	var argExp Arg
	for cutoff, argExp = range argsExp {
		if argExp.Optional() {
			break
		}
		if len(e.args) <= pos {
			return nil, ErrMissingArg
		}
		pos, err = e.consumeBasicArg(pos, argExp)
		if err != nil {
			return nil, err
		}
	}
	if !argExp.Optional() {
		cutoff++
	}

	// we stopped iterating the mandatory args.
	// any remaining args should be due to optional args otherwise there's too many
	// we also track here which keywords can also be used for the given optional args
	// so that those args should not be specified via their keys anymore.

	seenKwargs := make(map[string]struct{})
	for _, argOpt := range argsExp[cutoff:] {
		if len(e.args) <= pos {
			break // no more args specified. we're done.
		}
		pos, err = e.consumeBasicArg(pos, argOpt)
		if err != nil {
			return nil, err
		}
		seenKwargs[argOpt.Key()] = struct{}{}
	}
	if len(e.args) > pos {
		return nil, ErrTooManyArg
	}

	// for any provided keyword args, verify that they are what the function stipulated
	// and that they have not already been specified via their position
	for key := range e.namedArgs {
		_, ok := seenKwargs[key]
		if ok {
			return nil, ErrKwargSpecifiedTwice{key}
		}
		err = e.consumeKwarg(key, argsExp[cutoff:])
		if err != nil {
			return nil, err
		}
		seenKwargs[key] = struct{}{}
	}

	// functions now have their non-series input args set,
	// so they should now be able to specify any context alterations
	context = fn.Context(context)
	// now that we know the needed context for the data coming into
	// this function, we can set up the input arguments for the function
	// that are series
	pos = 0
	for _, argExp = range argsExp {
		if pos >= len(e.args) {
			break // no more args specified. we're done.
		}
		switch argExp.(type) {
		case ArgSeries, ArgSeriesList, ArgSeriesLists, ArgIn:
			pos, reqs, err = e.consumeSeriesArg(pos, argExp, context, stable, reqs)
			if err != nil {
				return nil, err
			}
		default:
			pos++
		}
	}
	return reqs, err
}
400593
func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int64, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
	uri := s.marketplaceURI(fmt.Sprintf("plans/%v/accounts", planID))
	u, err := addOptions(uri, opt)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	var accounts []*MarketplacePlanAccount
	resp, err := s.client.Do(ctx, req, &accounts)
	if err != nil {
		return nil, resp, err
	}

	return accounts, resp, nil
}
909933
func NewPlanQueue() (*PlanQueue, error) {
	q := &PlanQueue{
		enabled: false,
		stats:   new(QueueStats),
		ready:   make([]*pendingPlan, 0, 16),
		waitCh:  make(chan struct{}, 1),
	}
	return q, nil
}
136773
func (self *PlanClient) Create(params *PlanParams) (*Plan, error) {
	plan := Plan{}
	values := url.Values{
		"id":       {params.Id},
		"name":     {params.Name},
		"amount":   {strconv.FormatInt(params.Amount, 10)},
		"interval": {params.Interval},
		"currency": {params.Currency},
	}

	// trial_period_days is optional, add if specified
	if params.TrialPeriodDays != 0 {
		values.Add("trial_period_days", strconv.Itoa(params.TrialPeriodDays))
	}

	err := query("POST", "/v1/plans", values, &plan)
	return &plan, err
}
98601
func (qe *QueryEngine) GetMessageStreamPlan(name string) (*TabletPlan, error) {
	qe.mu.RLock()
	defer qe.mu.RUnlock()
	splan, err := planbuilder.BuildMessageStreaming(name, qe.tables)
	if err != nil {
		return nil, err
	}
	plan := &TabletPlan{Plan: splan}
	plan.Rules = qe.queryRuleSources.FilterByPlan("stream from "+name, plan.PlanID, plan.TableName().String())
	plan.buildAuthorized()
	return plan, nil
}
1143320
func NewPlanBuilder(sctx sessionctx.Context, is infoschema.InfoSchema) *PlanBuilder {
	return &PlanBuilder{
		ctx:       sctx,
		is:        is,
		colMapper: make(map[*ast.ColumnNameExpr]int),
	}
}
1266060
func MakeThriftSumEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		req := request.(addendpoint.SumRequest)
		reply, err := client.Sum(ctx, int64(req.A), int64(req.B))
		if err == addservice.ErrIntOverflow {
			return nil, err // special case; see comment on ErrIntOverflow
		}
		return addendpoint.SumResponse{V: int(reply.Value), Err: err}, nil
	}
}
1101649
func planBQL(ctx context.Context, bql string, s storage.Store, chanSize, bulkSize int, w io.Writer) (planner.Executor, error) {
	bql = strings.TrimSpace(bql)
	if bql == ";" {
		tracer.Trace(w, func() []string {
			return []string{"Empty statement found"}
		})
		return nil, nil
	}
	p, err := grammar.NewParser(grammar.SemanticBQL())
	if err != nil {
		msg := fmt.Errorf("NewParser failed; %v", err)
		tracer.Trace(w, func() []string {
			return []string{msg.Error()}
		})
		return nil, msg
	}
	stm := &semantic.Statement{}
	if err := p.Parse(grammar.NewLLk(bql, 1), stm); err != nil {
		msg := fmt.Errorf("NewLLk parser failed; %v", err)
		tracer.Trace(w, func() []string {
			return []string{msg.Error()}
		})
		return nil, msg
	}
	pln, err := planner.New(ctx, s, stm, chanSize, bulkSize, w)
	if err != nil {
		msg := fmt.Errorf("planer.New failed failed; %v", err)
		tracer.Trace(w, func() []string {
			return []string{msg.Error()}
		})
		return nil, msg
	}
	tracer.Trace(w, func() []string {
		return []string{"Plan successfuly created"}
	})
	return pln, nil
}
1174575
func buildControllerPlan(query string) (*controllerPlan, error) {
	stmt, err := sqlparser.Parse(query)
	if err != nil {
		return nil, err
	}
	switch stmt := stmt.(type) {
	case *sqlparser.Insert:
		return buildInsertPlan(stmt)
	case *sqlparser.Update:
		return buildUpdatePlan(stmt)
	case *sqlparser.Delete:
		return buildDeletePlan(stmt)
	case *sqlparser.Select:
		return buildSelectPlan(stmt)
	default:
		return nil, fmt.Errorf("unsupported construct: %s", sqlparser.String(stmt))
	}
}
672526
func (o *PolicyStatement) CreatePolicyEntry(child *PolicyEntry) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
127967
func (g *Virtual) AddCost(c int64) *Virtual {
	res := *g
	res.cost = Cost(c)
	res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		return g.visit(v, a, func(w int, _ int64) bool {
			return do(w, c)
		})
	}
	return &res
}
776450
func (p *ProxyLB) GetPlan() ProxyLBPlan {
	classes := strings.Split(p.ServiceClass, "/")
	class, err := strconv.Atoi(classes[len(classes)-1])
	if err != nil {
		return ProxyLBPlan1000
	}
	return ProxyLBPlan(class)
}
1197528
func (c Client) New(params *stripe.PlanParams) (*stripe.Plan, error) {
	plan := &stripe.Plan{}
	err := c.B.Call(http.MethodPost, "/v1/plans", c.Key, params, plan)
	return plan, err
}
299927
func (api *NFSAPI) CreateWithPlan(value *sacloud.CreateNFSValue, plan sacloud.NFSPlan, size sacloud.NFSSize) (*sacloud.NFS, error) {

	nfs := sacloud.NewNFS(value)
	// get plan
	plans, err := api.GetNFSPlans()
	if err != nil {
		return nil, err
	}
	if plans == nil {
		return nil, errors.New("NFS plans not found")
	}

	planID := plans.FindPlanID(plan, size)
	if planID < 0 {
		return nil, errors.New("NFS plans not found")
	}

	nfs.Plan = sacloud.NewResource(planID)
	nfs.Remark.SetRemarkPlanID(planID)

	return api.request(func(res *nfsResponse) error {
		return api.create(api.createRequest(nfs), res)
	})
}
96047
func (b *BigIP) CreatePolicy(p *Policy) error {
	normalizePolicy(p)
	return b.post(p, uriLtm, uriPolicy, policyVersionSuffix)
}
107804
func NewInsufficientPlan(Message string) *InsufficientPlan {
	s := new(InsufficientPlan)
	s.Message = Message
	return s
}