/**
 * Validation error detail from the API.
 * Matches the Go httpvalidation.ValidationDetail struct.
 */
export interface ValidationDetail {
  /** The field name that failed validation */
  field: string;
  /** Human-readable error message */
  message: string;
}

/**
 * Standard API error response structure.
 * Matches the Go httperror.HTTPError struct.
 */
export interface ApiError {
  /** HTTP status code */
  status: number;
  /** Machine-readable error code (e.g., "VALIDATION_ERROR", "NOT_FOUND") */
  code: string;
  /** Human-readable error message */
  message: string;
  /** Optional additional details (validation errors, etc.) */
  details?: ValidationDetail[] | Record<string, unknown>;
}

/**
 * Standard API response wrapper.
 */
export interface ApiResponse<T> {
  data?: T;
  error?: ApiError;
}

/**
 * Common error codes returned by the API.
 */
export const ErrorCode = {
  BAD_REQUEST: 'BAD_REQUEST',
  VALIDATION_ERROR: 'VALIDATION_ERROR',
  UNAUTHORIZED: 'UNAUTHORIZED',
  FORBIDDEN: 'FORBIDDEN',
  NOT_FOUND: 'NOT_FOUND',
  CONFLICT: 'CONFLICT',
  UNPROCESSABLE_ENTITY: 'UNPROCESSABLE_ENTITY',
  TOO_MANY_REQUESTS: 'TOO_MANY_REQUESTS',
  INTERNAL_ERROR: 'INTERNAL_ERROR',
  SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
} as const;

export type ErrorCodeType = (typeof ErrorCode)[keyof typeof ErrorCode];

/**
 * Auth-related types for login/user responses.
 */
export interface AuthUser {
  id: string;
  email: string;
  name?: string;
  roles?: string[];
  scopes?: string[];
}

export interface LoginResponse {
  token: string;
  user: AuthUser;
}
