package Nmysql

import (
	// "fmt"
	l4g "proxy/logger"
)

func SetAlertSmsState2Sent(alertId int) error {
	stmt, _ := MySqlDb.Prepare("update tb_sms_info set sms_state=2 where sms_alert_id=?;")
	defer stmt.Close()

	_, err := stmt.Exec(alertId)
	if err != nil {
		l4g.MysqlLog.Errorf("SetAlertSmsState2Sent err: %v", err)
		return err
	}

	l4g.MysqlLog.Debugf("SetAlertSmsState2Sent succ!")
	return nil
}

func InsertExpiredNotifySms(accountId uint32, planId uint32, expiredDate int64) error {
	stmt, _ := MySqlDb.Prepare("INSERT into tb_sync_msg SET msg_type=1, acct_id=?, ofr_inst_id=?, exp_date=FROM_UNIXTIME(?), state=1;")
	defer stmt.Close()

	_, err := stmt.Exec(accountId, planId, expiredDate)
	if err != nil {
		l4g.MysqlLog.Errorf("InsertExpiredNotifySms acctId[%d], planId[%d], expiredDate[%d] err: %v", accountId, planId, expiredDate, err)
		return err
	}

	l4g.MysqlLog.Debugf("InsertExpiredNotifySms acctId[%d], planId[%d], expiredDate[%d] succ!", accountId, planId, expiredDate)
	return nil
}

