package controller

import (
	"bswas/utilities"
	"strconv"
)

func PackageCreateExceptionFormat(data []map[string]string) ([]interface{}, [][]interface{})  {
	row := []interface{}{
		"快递单号","承运商","设备","称重时间","重(KG)","长(CM)","宽(CM)","高(CM)","体积(CM³)",
		"纸箱","异常类型",
	}
	column := map[string]int{
		"logistic_number" : 0,
		"logistic_name" : 1,
		"measuring_machine_name" : 2,
		"weigh_time" : 3,
		"weight" : 4,
		"length" : 5,
		"width" : 6,
		"height" : 7,
		"bulk" : 8,
		"paper_box_name" : 9,
		"status" : 10,
	}
	list := make([][]interface{},len(data))
	for k,v := range data{
		line := make([]interface{},len(row))
		for key,value := range column {
			line[value] = v[key]
		}
		list[k] = line
	}
	return row,list
}
func PackageIssuedExceptionFormat(data []map[string]string) ([]interface{}, [][]interface{})  {
	row := []interface{}{
		"快递单号","下发时间","发货单号","波次号","波次规则","收件人","收件人电话","承运商","异常类型",
	}
	column := map[string]int{
		"logistic_number" : 0,
		"created_at" : 1,
		"delivery_number" : 2,
		"batch_number" : 3,
		"batch_rule" : 4,
		"recipient" : 5,
		"recipient_mobile" : 6,
		"logistic_name" : 7,
		"status" : 8,
	}
	list := make([][]interface{},len(data))
	for k,v := range data{
		line := make([]interface{},len(row))
		for key,value := range column {
			if key == "created_at"{
				line[value] = utilities.DateFormat(v[key],"2006-01-02T15:04:05Z")
				continue
			}
			line[value] = v[key]
		}
		list[k] = line
	}
	return row,list
}

func PackageStatisticFormat(ROW []interface{},LIST []map[int]string) ([]interface{}, [][]interface{}) {
	list := make([][]interface{},len(LIST))
	for k,v := range LIST {
		line := make([]interface{},len(ROW))
		amount := 0
		for index,_ := range ROW {
			_,sign := v[index]
			if sign {
				if index > 1 {
					number,_ := strconv.Atoi(v[index])
					amount += number
				}
				line[index] = v[index]
			}else{
				line[index] = "0"
			}
		}
		line[1] = amount
		list[k] = line
	}
	return ROW,list
}