export type AdminModuleStatus = 'live' | 'mock' | 'pending';

export type VerificationStatus = 'PENDING' | 'IN_REVIEW' | 'VERIFIED' | 'REJECTED' | 'FLAGGED';
export type ApprovalStatus = 'PENDING_APPROVAL' | 'IN_REVIEW' | 'APPROVED' | 'REJECTED' | 'ON_HOLD' | 'ESCALATED';

export type VerificationPriority = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';

export type VerificationCase = {
  id: string;
  applicantName: string;
  userType: string;
  verificationType: string;
  submittedAt: string;
  documents: number;
  status: VerificationStatus;
  priority: VerificationPriority;
};

export type ApprovalCase = {
  id: string;
  applicantName: string;
  approvalType: string;
  userType: string;
  submittedAt: string;
  verificationStatus: Extract<VerificationStatus, 'VERIFIED' | 'REJECTED' | 'FLAGGED'>;
  status: ApprovalStatus;
  priority: VerificationPriority;
};

export type CrudRecord = {
  id: string;
  name: string;
  status: string;
  updatedAt: string;
  [key: string]: unknown;
};

export type AdminModuleConfig = {
  route: string;
  title: string;
  navLabel: string;
  category: 'core' | 'org' | 'access' | 'governance' | 'entities' | 'commerce';
  status: AdminModuleStatus;
  description: string;
};

export type ListQuery = {
  q?: string;
  status?: string;
};

export interface CrudService<T> {
  list(query?: ListQuery): Promise<T[]>;
  detail(id: string): Promise<T | null>;
  create(payload: Partial<T>): Promise<T>;
  update(id: string, payload: Partial<T>): Promise<T>;
  delete(id: string): Promise<boolean>;
  bulkAction(ids: string[], action: string): Promise<{ ok: boolean; count: number }>;
}

export const toApprovalEligibility = (
  status: VerificationStatus,
): Extract<ApprovalStatus, 'PENDING_APPROVAL' | 'REJECTED' | 'ESCALATED'> | null => {
  if (status === 'VERIFIED') return 'PENDING_APPROVAL';
  if (status === 'REJECTED') return 'REJECTED';
  if (status === 'FLAGGED') return 'ESCALATED';
  return null;
};
