package service

import (
	"context"
	"youngee_b_api/db"
	"youngee_b_api/model/http_model"

	log "github.com/sirupsen/logrus"
)

var Pay *pay

type pay struct {
}

func (*pay) GetPaysum(ctx context.Context, project http_model.PaySumRequest) (*http_model.PaySumResponce, error) {
	//select　* from　taskinfo where project_id = project.project_id => []task
	//map int float
	//for t in task:
	projectId := project.ProjectId
	tasks, err := db.GetTaskList(ctx, projectId)
	if err != nil {
		log.Infof("[GetPayTasklist] fail,err:%+v", err)
		return nil, err
	}
	payMap := make(map[int]float64)
	recruitStrategys, err := db.GetRecruitStrategyByProjectId(ctx, projectId)
	for _, v := range recruitStrategys {
		payMap[int(v.StrategyID)] = 0
	}
	PaySum := http_model.PaySumResponce{}
	if tasks != nil {
		for _, task := range tasks {
			payMap[task.StrategyID] += task.AllPayment
		}
		for k, v := range payMap {
			ps := http_model.PaySum{k, v}
			PaySum.PaySum = append(PaySum.PaySum, ps)
		}
	}
	return &PaySum, nil
}
