package steme

import (
	"errors"
	"fmt"
)

var (
	// ErrInvalidKeySize indicates the private key is not 32 bytes
	ErrInvalidKeySize = errors.New("steme: private key must be exactly 32 bytes")

	// ErrInvalidPublicKeySize indicates the public key is not 32 bytes
	ErrInvalidPublicKeySize = errors.New("steme: public key must be exactly 32 bytes")

	// ErrInvalidSignatureSize indicates the signature is not 64 bytes
	ErrInvalidSignatureSize = errors.New("steme: signature must be exactly 64 bytes")

	// ErrInvalidHashSize indicates a hash is not 32 bytes
	ErrInvalidHashSize = errors.New("steme: hash must be exactly 32 bytes")

	// ErrMissingSignatures indicates no signatures were provided
	ErrMissingSignatures = errors.New("steme: at least one signature is required")

	// ErrInvalidConfidence indicates confidence is not in [0.0, 1.0]
	ErrInvalidConfidence = errors.New("steme: confidence must be between 0.0 and 1.0")

	// ErrInvalidHex indicates hex decoding failed
	ErrInvalidHex = errors.New("steme: invalid hex encoding")

	// ErrNoWinner indicates lens failed to resolve a winner
	ErrNoWinner = errors.New("steme: lens did not resolve a winner")
)

// APIError wraps HTTP API errors with status code and message.
type APIError struct {
	StatusCode int
	Code       string
	Message    string
}

func (e *APIError) Error() string {
	return fmt.Sprintf("steme API error [%d]: %s - %s", e.StatusCode, e.Code, e.Message)
}

// ValidationError indicates a request validation failure.
type ValidationError struct {
	Field   string
	Message string
}

func (e *ValidationError) Error() string {
	return fmt.Sprintf("steme validation error: %s - %s", e.Field, e.Message)
}
