package myth

import (
	"database/sql"
	"errors"
)

// Error error
type Error struct {
	c int
	s string
}

// NewError new
func NewError(code int, text string) *Error {
	return &Error{c: code, s: text}
}

// Code err code
func (e *Error) Code() int {
	return e.c
}

// Error err to string
func (e *Error) Error() string {
	return e.s
}

// Unwrap return error
func (e *Error) Unwrap() error {
	return errors.New(e.s)
}

// Is reports whether any error in err's chain matches target.
func (e *Error) Is(err error) bool {
	return errors.Is(errors.New(e.s), err)
}

// ErrSQLNoRows SQL
func ErrSQLNoRows(e error) bool {
	return errors.Is(e, sql.ErrNoRows)
}