package model

import (
	"crawler/config"
	"crawler/service"
)

type G2AErrorModel struct {
	G2AError
}

type G2AError struct {
	Status  string `json:"status"`
	Message string `json:"message"`
	Code    string `json:"code"`
	URL     string `json:"url"`
	Params  string `json:"params"`
}

func (this *G2AErrorModel) Save() {
	var (
		db   = service.DB_PLAYR
		conn = db.SQLDB
	)

	sql := `
		INSERT INTO tb_g2a_error
		SET 
			status = ?,
			message = ?,
			code = ?,
			url = ?,
			params = ?,
			created_at = NOW();
	`
	_, err := conn.Exec(sql, this.Status, this.Message, this.Code, this.URL, this.Params)
	if err != nil {
		db.SetErrorLog(err, sql)
	}

	db.SetGeneralLog(config.GL_ACTION_WRITE, sql, "insert g2a error")
}
