/*

 Copyright (c) [2023] [pcm]
 [pcm-coordinator] is licensed under Mulan PSL v2.
 You can use this software according to the terms and conditions of the Mulan PSL v2.
 You may obtain a copy of Mulan PSL v2 at:
          http://license.coscl.org.cn/MulanPSL2
 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 See the Mulan PSL v2 for more details.

*/

package providerPricing

import (
	"math"
)

type Provider struct {
	Pid           int64
	CpuSum        float64
	MemSum        float64
	DiskSum       float64
	CpuCost       float64
	MemCost       float64
	DiskCost      float64
	CpuAvail      float64
	MemAvail      float64
	DiskAvail     float64
	CurReplicas   int
	MaxReplicas   int
	MaxTaskCanRun int     //记录该厂商针对当前可以接收的最大任务数
	TrustDegree   float64 //信任度取值为0到1，默认初始为1
	LearnIndex    float64 //云厂商生产成本的学习指数
	PartWill      float64 //合作意愿
	ProfitSum     float64
	ProfitPerTask map[int]float64
}

func NewProvider(Pid int64, CpuSum float64, MemSum float64, DiskSum float64, CpuCost float64, MemCost float64, DiskCost float64) *Provider {
	return &Provider{
		Pid:        Pid,
		CpuSum:     CpuSum,
		MemSum:     MemSum,
		DiskSum:    DiskSum,
		CpuCost:    CpuCost,
		MemCost:    MemCost,
		DiskCost:   DiskCost,
		CpuAvail:   CpuSum,
		MemAvail:   MemSum,
		DiskAvail:  DiskSum,
		LearnIndex: 0.9,
		PartWill:   1,
	}
}

func (p *Provider) GenMaxResourceNum(t *Task) {
	p.MaxReplicas = int(math.Floor(p.CpuAvail / t.Cpu))

	if p.MaxReplicas > int(math.Floor(p.MemAvail/t.Mem)) {
		p.MaxReplicas = int(math.Floor(p.MemAvail / t.Mem))
	}
	if p.MaxReplicas > int(math.Floor(p.DiskAvail/t.Disk)) {
		p.MaxReplicas = int(math.Floor(p.DiskAvail / t.Disk))
	}

	if p.MaxReplicas > 0 {
		p.MaxTaskCanRun = t.Replicas
	}
}

func (p Provider) name() {

}
