package inquiry

import "errors"

// Inquiry-specific errors
var (
	ErrDuplicateInquiryByEmail = errors.New("duplicate inquiry by email")
	ErrDuplicateInquiryByPhone = errors.New("duplicate inquiry by phone")
	ErrInquiryNotFound         = errors.New("inquiry not found")
	ErrInvalidStatusTransition = errors.New("invalid status transition")
	ErrInquiryAlreadyProcessed = errors.New("inquiry already processed")
)

// DuplicateInquiryError represents a duplicate inquiry error with details
type DuplicateInquiryError struct {
	Type        string `json:"type"`        // "email" or "phone"
	ExistingID  string `json:"existing_id"` // ID of existing inquiry
	Status      string `json:"status"`      // Status of existing inquiry
	CreatedAt   int64  `json:"created_at"`  // When existing inquiry was created
	Message     string `json:"message"`     // User-friendly message
}

func (e *DuplicateInquiryError) Error() string {
	return e.Message
}

// NewDuplicateInquiryError creates a new duplicate inquiry error
func NewDuplicateInquiryError(inquiryType, existingID, status string, createdAt int64) *DuplicateInquiryError {
	var message string
	if inquiryType == "email" {
		message = "You already have a pending inquiry with this email address. Please wait for it to be processed before submitting a new one."
	} else {
		message = "A pending inquiry already exists with this phone number. Please wait for it to be processed before submitting a new one."
	}

	return &DuplicateInquiryError{
		Type:       inquiryType,
		ExistingID: existingID,
		Status:     status,
		CreatedAt:  createdAt,
		Message:    message,
	}
}
