import { notifications } from '@mantine/notifications';
import { NotificationConfig } from '../types';

export const showSuccessNotification = (message: string, title = 'Success') => {
  const config: NotificationConfig = {
    title,
    message,
    color: 'green',
  };
  notifications.show(config);
};

export const showErrorNotification = (message: string, title = 'Error') => {
  const config: NotificationConfig = {
    title,
    message,
    color: 'red',
  };
  notifications.show(config);
};

export const showWarningNotification = (message: string, title = 'Warning') => {
  const config: NotificationConfig = {
    title,
    message,
    color: 'yellow',
  };
  notifications.show(config);
};

export const showInfoNotification = (message: string, title = 'Info') => {
  const config: NotificationConfig = {
    title,
    message,
    color: 'blue',
  };
  notifications.show(config);
};

// Common notification messages used across microfrontends
export const NotificationMessages = {
  // Generic CRUD operations
  createSuccess: (entityName: string) => `${entityName} created successfully`,
  updateSuccess: (entityName: string) => `${entityName} updated successfully`,
  deleteSuccess: (entityName: string) => `${entityName} deleted successfully`,
  
  createError: (entityName: string) => `Failed to create ${entityName}`,
  updateError: (entityName: string) => `Failed to update ${entityName}`,
  deleteError: (entityName: string) => `Failed to delete ${entityName}`,
  
  loadError: (entityName: string) => `Failed to load ${entityName}`,
  networkError: 'Network error occurred. Please try again.',
  
  // Validation
  validationError: 'Please check the form for errors',
  requiredFieldError: (fieldName: string) => `${fieldName} is required`,
  
  // Authentication
  authRequired: 'Authentication required',
  permissionDenied: 'Permission denied',
  sessionExpired: 'Session expired. Please log in again.',
  
  // Application-specific
  applicationCreated: 'Application created successfully',
  applicationUpdated: 'Application updated successfully',
  applicationDeleted: 'Application deleted successfully',
  
  tokenCreated: 'Token created successfully',
  tokenRevoked: 'Token revoked successfully',
  
  userCreated: 'User created successfully',
  userUpdated: 'User updated successfully',
  userDeleted: 'User deleted successfully',
  
  functionCreated: 'Function created successfully',
  functionUpdated: 'Function updated successfully',
  functionDeleted: 'Function deleted successfully',
  
  executionStarted: 'Function execution started',
  executionCompleted: 'Function execution completed',
  executionFailed: 'Function execution failed',
};

// Utility to show notifications for common operations
export const showCrudNotification = {
  success: (operation: 'create' | 'update' | 'delete', entityName: string) => {
    const message = NotificationMessages[`${operation}Success`](entityName);
    showSuccessNotification(message);
  },
  
  error: (operation: 'create' | 'update' | 'delete' | 'load', entityName: string, customMessage?: string) => {
    const message = customMessage || NotificationMessages[`${operation}Error`](entityName);
    showErrorNotification(message);
  },
};