// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.package spec

package server

import (
	"net/http"

	"github.com/pingcap/tidb-cloud-manager/pkg/manager"
	tiapi "github.com/pingcap/tidb-cloud-manager/pkg/tidbinstance/api"
)

func newResponse(action string) *Response {
	return &Response{Action: action, StatusCode: http.StatusOK}
}

func (r *Response) statusCode(code int) *Response {
	r.StatusCode = code
	return r
}

func (r *Response) message(msg string) *Response {
	r.Message = msg
	return r
}

func (r *Response) payload(payload Payload) *Response {
	r.Payload = payload
	return r
}

func needResize(instance *tiapi.TidbInstance, cluster *manager.Cluster) bool {
	if cluster.Pd.Size != 0 && cluster.Pd.Size != instance.Spec.PD.Size {
		return true
	}
	if cluster.Tidb.Size != 0 && cluster.Tidb.Size != instance.Spec.TiDB.Size {
		return true
	}
	if cluster.Tikv.Size != 0 && cluster.Tikv.Size != instance.Spec.TiKV.Size {
		return true
	}
	return false
}
