package actions

import (
	"encoding/json"
	"fmt"
	"time"
	"zzman/clients/jd"
	"zzman/model"
)

func RecordSubmit(time time.Time, gatewat model.Gateway, edges []jd.EdgeInfo) error {
	config, err := json.Marshal(edges)
	if err != nil {
		return fmt.Errorf("序列化提交数据失败：%w", err)
	}

	err = model.DB.Create(&model.Submit{
		Time:    time,
		Gateway: gatewat.Macaddr,
		Config:  string(config),
	}).Error
	if err != nil {
		return fmt.Errorf("保存提交记录失败：%w", err)
	}

	return nil
}
