/**
 * Base validation types for order validators
 */

/**
 * Validation error details
 */
export interface ValidationError {
  /** Error code for programmatic handling */
  code: string;
  /** Human-readable error message */
  message: string;
  /** Optional field that caused the error */
  field?: string;
}

/**
 * Result of a validation operation
 */
export interface ValidationResult<T = void> {
  /** Whether validation passed */
  success: boolean;
  /** Data returned on success (optional) */
  data?: T;
  /** Errors on failure */
  errors?: ValidationError[];
}

/**
 * Create a successful validation result
 */
export function validationSuccess(): ValidationResult<void>;
export function validationSuccess<T>(data: T): ValidationResult<T>;
export function validationSuccess<T>(data?: T): ValidationResult<T> {
  if (data === undefined) {
    return { success: true } as ValidationResult<T>;
  }
  return { success: true, data };
}

/**
 * Create a failed validation result
 */
export function validationFailure(errors: ValidationError[]): ValidationResult<never> {
  return { success: false, errors };
}

/**
 * Create a single validation error
 */
export function createValidationError(
  code: string,
  message: string,
  field?: string
): ValidationError {
  const error: ValidationError = { code, message };
  if (field !== undefined) {
    error.field = field;
  }
  return error;
}

/**
 * Common validation error codes
 */
export const ValidationErrorCode = {
  // User mapping errors
  USER_MAPPING_NOT_FOUND: "USER_MAPPING_NOT_FOUND",
  WHMCS_CLIENT_NOT_LINKED: "WHMCS_CLIENT_NOT_LINKED",

  // Payment errors
  NO_PAYMENT_METHOD: "NO_PAYMENT_METHOD",

  // SKU errors
  INVALID_SKU: "INVALID_SKU",
  MISSING_REQUIRED_SKU: "MISSING_REQUIRED_SKU",

  // SIM order errors
  RESIDENCE_CARD_NOT_SUBMITTED: "RESIDENCE_CARD_NOT_SUBMITTED",
  RESIDENCE_CARD_REJECTED: "RESIDENCE_CARD_REJECTED",
  SIM_ACTIVATION_FEE_REQUIRED: "SIM_ACTIVATION_FEE_REQUIRED",

  // Internet order errors
  INTERNET_ELIGIBILITY_NOT_REQUESTED: "INTERNET_ELIGIBILITY_NOT_REQUESTED",
  INTERNET_ELIGIBILITY_PENDING: "INTERNET_ELIGIBILITY_PENDING",
  INTERNET_INELIGIBLE: "INTERNET_INELIGIBLE",
  INTERNET_SERVICE_EXISTS: "INTERNET_SERVICE_EXISTS",
  INTERNET_CHECK_FAILED: "INTERNET_CHECK_FAILED",

  // General errors
  VALIDATION_ERROR: "VALIDATION_ERROR",
} as const;
