/**
 * Issue Management Constants
 *
 * Configuration for status, priority, and workflow.
 *
 * @module features/issues/constants
 */

import type {
  IssueStatus,
  IssuePriority,
  StatusConfig,
  PriorityConfig,
  StatusTransition,
} from './types';

/**
 * Status configuration with labels and colors
 */
export const STATUS_CONFIG: Record<IssueStatus, StatusConfig> = {
  open: { label: 'Open', color: 'text-blue-500' },
  in_progress: { label: 'In Progress', color: 'text-yellow-500' },
  in_review: { label: 'In Review', color: 'text-purple-500' },
  blocked: { label: 'Blocked', color: 'text-red-500' },
  closed: { label: 'Closed', color: 'text-green-500' },
};

/**
 * Priority configuration with labels and colors
 */
export const PRIORITY_CONFIG: Record<IssuePriority, PriorityConfig> = {
  critical: {
    label: 'Critical',
    color: 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200',
  },
  high: { label: 'High', color: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200' },
  medium: {
    label: 'Medium',
    color: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200',
  },
  low: { label: 'Low', color: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200' },
};

/**
 * Status workflow transitions
 * Defines which status transitions are available from each status
 */
export const STATUS_TRANSITIONS: StatusTransition[] = [
  { from: 'open', to: 'in_progress', label: 'Start Work' },
  { from: 'in_progress', to: 'in_review', label: 'Submit for Review' },
  { from: 'in_progress', to: 'blocked', label: 'Mark Blocked' },
  { from: 'in_review', to: 'closed', label: 'Complete' },
  { from: 'in_review', to: 'in_progress', label: 'Request Changes' },
  { from: 'blocked', to: 'in_progress', label: 'Unblock' },
  { from: 'closed', to: 'open', label: 'Reopen' },
];

/**
 * Get available transitions for a given status
 */
export function getAvailableTransitions(currentStatus: IssueStatus): StatusTransition[] {
  return STATUS_TRANSITIONS.filter((t) => t.from === currentStatus);
}

/**
 * Get primary transition for a given status (the main workflow action)
 */
export function getPrimaryTransition(currentStatus: IssueStatus): StatusTransition | undefined {
  const transitions = getAvailableTransitions(currentStatus);
  return transitions[0];
}

/**
 * All possible statuses in workflow order
 */
export const STATUS_ORDER: IssueStatus[] = [
  'open',
  'in_progress',
  'in_review',
  'blocked',
  'closed',
];

/**
 * All possible priorities in order
 */
export const PRIORITY_ORDER: IssuePriority[] = ['critical', 'high', 'medium', 'low'];

/**
 * Sync status configuration
 */
export const SYNC_STATUS_CONFIG = {
  synced: { label: 'Synced', color: 'text-green-500' },
  pending: { label: 'Syncing', color: 'text-yellow-500' },
  conflict: { label: 'Conflict', color: 'text-orange-500' },
  error: { label: 'Sync Error', color: 'text-red-500' },
} as const;

/**
 * Default page size for issue list
 */
export const DEFAULT_PAGE_SIZE = 25;

/**
 * Maximum issues for bulk actions
 */
export const MAX_BULK_SELECTION = 100;
