package com.example.petstoremobile.utils;

import android.content.Context;
import androidx.appcompat.app.AlertDialog;

/**
 * Utility class for creating and displaying common dialogs.
 */
public class DialogUtils {

    /**
     * Interface for handling dialog button clicks.
     */
    public interface DialogCallback {
        void onConfirm();
    }

    /**
     * Shows a confirmation dialog with "Yes" and "No" buttons.
     */
    public static void showConfirmDialog(Context context, String title, String message, DialogCallback callback) {
        new AlertDialog.Builder(context)
                .setTitle(title)
                .setMessage(message)
                .setPositiveButton("Yes", (dialog, which) -> callback.onConfirm())
                .setNegativeButton("No", null)
                .show();
    }

    /**
     * Shows a delete confirmation dialog.
     */
    public static void showDeleteConfirmDialog(Context context, String itemName, DialogCallback callback) {
        showConfirmDialog(context, "Delete " + itemName + "?", "Are you sure you want to delete this " + itemName.toLowerCase() + "? This action cannot be undone.", callback);
    }

    /**
     * Shows a confirmation dialog with specific "Delete" and "Cancel" buttons.
     */
    public static void showBulkDeleteConfirmDialog(Context context, int count, DialogCallback callback) {
        new AlertDialog.Builder(context)
                .setTitle("Delete " + count + " item(s)?")
                .setMessage("This cannot be undone.")
                .setPositiveButton("Delete", (dialog, which) -> callback.onConfirm())
                .setNegativeButton("Cancel", null)
                .show();
    }

    /**
     * Shows a simple information or error dialog with an "OK" button.
     */
    public static void showInfoDialog(Context context, String title, String message) {
        new AlertDialog.Builder(context)
                .setTitle(title)
                .setMessage(message)
                .setPositiveButton("OK", null)
                .show();
    }
}
