package sms

import "fmt"

// SMSError 短信服务错误
type SMSError struct {
	Code    int    // 错误码
	Message string // 错误消息
}

// Error 实现 error 接口
func (e *SMSError) Error() string {
	return fmt.Sprintf("SMS error (code=%d): %s", e.Code, e.Message)
}

// NewSMSError 创建短信服务错误
func NewSMSError(code int, message string) *SMSError {
	return &SMSError{
		Code:    code,
		Message: message,
	}
}

// IsInsufficientBalance 判断是否为余额不足错误
func (e *SMSError) IsInsufficientBalance() bool {
	return e.Code == CodeInsufficientBalance
}

// IsAuthError 判断是否为认证错误
func (e *SMSError) IsAuthError() bool {
	return e.Code == CodeAuthFailed || e.Code == CodeAccountLocked || e.Code == CodeBusinessNotOpened
}

// IsTimestampError 判断是否为时间戳错误
func (e *SMSError) IsTimestampError() bool {
	return e.Code == CodeTimestampError
}
