import { defineEnum } from './define-enum';

type Values = readonly [string, ...string[]];

const labelsFor = <V extends Values>(values: V): Record<V[number], string> =>
  Object.fromEntries(values.map((value) => [value, value.toLowerCase()])) as Record<
    V[number],
    string
  >;

export const ACCOUNT_STATE_USER = ['ACTIVE', 'FROZEN', 'DELETED_PENDING', 'DELETED'] as const;
export const accountStateUser = defineEnum({
  name: 'account_state_user',
  values: ACCOUNT_STATE_USER,
  labels: labelsFor(ACCOUNT_STATE_USER),
});
export type AccountStateUser = (typeof ACCOUNT_STATE_USER)[number];

export const LLM_JOB_TYPE = [
  'DEAL_MODERATION',
  'IMAGE_APPROVAL',
  'REVIEW_PRESCORING',
  'VENDOR_VIOLATION',
  'TRANSLATION',
] as const;
export const llmJobType = defineEnum({
  name: 'llm_job_type',
  values: LLM_JOB_TYPE,
  labels: labelsFor(LLM_JOB_TYPE),
});
export type LlmJobType = (typeof LLM_JOB_TYPE)[number];

export const LLM_JOB_STATUS = ['PENDING', 'RUNNING', 'COMPLETED', 'FAILED', 'TIMED_OUT'] as const;
export const llmJobStatus = defineEnum({
  name: 'llm_job_status',
  values: LLM_JOB_STATUS,
  labels: labelsFor(LLM_JOB_STATUS),
});
export type LlmJobStatus = (typeof LLM_JOB_STATUS)[number];

export const LLM_DECISION = ['APPROVE', 'FLAG', 'REJECT'] as const;
export const llmDecision = defineEnum({
  name: 'llm_decision',
  values: LLM_DECISION,
  labels: labelsFor(LLM_DECISION),
});
export type LlmDecision = (typeof LLM_DECISION)[number];

export const LLM_TARGET_TYPE = [
  'DEAL',
  'IMAGE',
  'REVIEW_REMOVAL',
  'VENDOR',
  'CATEGORY',
  'TAG',
  'REVIEW',
] as const;
export const llmTargetType = defineEnum({
  name: 'llm_target_type',
  values: LLM_TARGET_TYPE,
  labels: labelsFor(LLM_TARGET_TYPE),
});
export type LlmTargetType = (typeof LLM_TARGET_TYPE)[number];

export const APPEAL_STATUS = ['PENDING', 'APPROVED', 'REJECTED'] as const;
export const appealStatus = defineEnum({
  name: 'appeal_status',
  values: APPEAL_STATUS,
  labels: labelsFor(APPEAL_STATUS),
});
export type AppealStatus = (typeof APPEAL_STATUS)[number];

export const APPROVED_BY = ['HUMAN', 'AI_AGENT'] as const;
export const approvedBy = defineEnum({
  name: 'approved_by',
  values: APPROVED_BY,
  labels: labelsFor(APPROVED_BY),
});
export type ApprovedBy = (typeof APPROVED_BY)[number];

export const IMAGE_APPROVAL_STATUS = ['PENDING', 'APPROVED', 'REJECTED'] as const;
export const imageApprovalStatus = defineEnum({
  name: 'image_approval_status',
  values: IMAGE_APPROVAL_STATUS,
  labels: labelsFor(IMAGE_APPROVAL_STATUS),
});
export type ImageApprovalStatus = (typeof IMAGE_APPROVAL_STATUS)[number];

export const REVIEW_TYPE = ['STANDARD', 'TECHNICAL'] as const;
export const reviewType = defineEnum({
  name: 'review_type',
  values: REVIEW_TYPE,
  labels: labelsFor(REVIEW_TYPE),
});
export type ReviewType = (typeof REVIEW_TYPE)[number];

export const REMOVAL_STATUS = ['NONE', 'PENDING', 'APPROVED', 'REJECTED'] as const;
export const removalStatus = defineEnum({
  name: 'removal_status',
  values: REMOVAL_STATUS,
  labels: labelsFor(REMOVAL_STATUS),
});
export type RemovalStatus = (typeof REMOVAL_STATUS)[number];

export const REMOVED_BY = ['HUMAN', 'AI_AGENT'] as const;
export const removedBy = defineEnum({
  name: 'removed_by',
  values: REMOVED_BY,
  labels: labelsFor(REMOVED_BY),
});
export type RemovedBy = (typeof REMOVED_BY)[number];

export const ADMIN_TARGET_TYPE = [
  'DEAL',
  'VENDOR',
  'REVIEW',
  'USER',
  'PURCHASE',
  'KB_ARTICLE',
  'SETTING',
  'OUTBOX_EVENT',
  'IMAGE',
  'SETTLEMENT',
] as const;
export const adminTargetType = defineEnum({
  name: 'admin_target_type',
  values: ADMIN_TARGET_TYPE,
  labels: labelsFor(ADMIN_TARGET_TYPE),
});
export type AdminTargetType = (typeof ADMIN_TARGET_TYPE)[number];

export const IMAGE_ENTITY_TYPE = [
  'vendor',
  'deal',
  'user',
  'page_module',
  'support_ticket',
] as const;
export const imageEntityType = defineEnum({
  name: 'image_entity_type',
  values: IMAGE_ENTITY_TYPE,
  labels: labelsFor(IMAGE_ENTITY_TYPE),
});
export type ImageEntityType = (typeof IMAGE_ENTITY_TYPE)[number];

export const AI_DECISION = ['PASS', 'FLAG', 'REJECT', 'ERROR'] as const;
export const aiDecision = defineEnum({
  name: 'ai_decision',
  values: AI_DECISION,
  labels: labelsFor(AI_DECISION),
});
export type AiDecision = (typeof AI_DECISION)[number];

export const NOTIFICATION_SEVERITY = ['info', 'warning', 'error'] as const;
export const notificationSeverity = defineEnum({
  name: 'notification_severity',
  values: NOTIFICATION_SEVERITY,
  labels: labelsFor(NOTIFICATION_SEVERITY),
});
export type NotificationSeverity = (typeof NOTIFICATION_SEVERITY)[number];

export const ADMIN_ACTION = [
  'APPROVE',
  'REJECT',
  'FREEZE',
  'UNFREEZE',
  'BAN',
  'REMOVE_REVIEW',
  'RESTORE_REVIEW',
  'ADD_QUANTITY',
  'GRANT_ADMIN',
  'REVOKE_ADMIN',
  'REQUEST_REFUND',
  'RESEND_RECEIPT',
  'KB_CREATE',
  'KB_UPDATE',
  'KB_DELETE',
  'SETTING_UPDATE',
  'OUTBOX_RETRY',
  'MARK_PAID',
  'MARK_PENDING',
] as const;
export const adminAction = defineEnum({
  name: 'admin_action',
  values: ADMIN_ACTION,
  labels: labelsFor(ADMIN_ACTION),
});
export type AdminAction = (typeof ADMIN_ACTION)[number];

export const SENDER_TYPE = ['USER', 'VENDOR'] as const;
export const senderType = defineEnum({
  name: 'sender_type',
  values: SENDER_TYPE,
  labels: labelsFor(SENDER_TYPE),
});
export type SenderType = (typeof SENDER_TYPE)[number];

export const PERSONAL_DEAL_STATUS = ['PENDING', 'ACCEPTED', 'REJECTED', 'EXPIRED'] as const;
export const personalDealStatus = defineEnum({
  name: 'personal_deal_status',
  values: PERSONAL_DEAL_STATUS,
  labels: labelsFor(PERSONAL_DEAL_STATUS),
});
export type PersonalDealStatus = (typeof PERSONAL_DEAL_STATUS)[number];

export const REPORT_TARGET_TYPE = ['VENDOR', 'DEAL', 'REVIEW', 'USER'] as const;
export const reportTargetType = defineEnum({
  name: 'report_target_type',
  values: REPORT_TARGET_TYPE,
  labels: labelsFor(REPORT_TARGET_TYPE),
});
export type ReportTargetType = (typeof REPORT_TARGET_TYPE)[number];

export const REPORT_REASON = [
  'FACTUAL_ERROR',
  'MISLEADING',
  'WRONG_HOURS',
  'BUG',
  'OTHER',
] as const;
export const reportReason = defineEnum({
  name: 'report_reason',
  values: REPORT_REASON,
  labels: labelsFor(REPORT_REASON),
});
export type ReportReason = (typeof REPORT_REASON)[number];

export const REPORT_STATUS = ['OPEN', 'INVESTIGATING', 'RESOLVED', 'DISMISSED'] as const;
export const reportStatus = defineEnum({
  name: 'report_status',
  values: REPORT_STATUS,
  labels: labelsFor(REPORT_STATUS),
});
export type ReportStatus = (typeof REPORT_STATUS)[number];

export const REVIEW_REMOVAL_QUEUE_STATUS = ['PENDING', 'APPROVED', 'REJECTED'] as const;
export const reviewRemovalQueueStatus = defineEnum({
  name: 'review_removal_queue_status',
  values: REVIEW_REMOVAL_QUEUE_STATUS,
  labels: labelsFor(REVIEW_REMOVAL_QUEUE_STATUS),
});
export type ReviewRemovalQueueStatus = (typeof REVIEW_REMOVAL_QUEUE_STATUS)[number];

export const RESERVATION_STATUS = [
  'HELD',
  'CAPTURED',
  'RELEASED',
  'CANCELLED',
  'WAITLISTED',
  'HOLD_EXPIRED',
] as const;
export const reservationStatus = defineEnum({
  name: 'reservation_status',
  values: RESERVATION_STATUS,
  labels: labelsFor(RESERVATION_STATUS),
});
export type ReservationStatus = (typeof RESERVATION_STATUS)[number];

export const SUPPORT_PARENT_TYPE = ['ticket', 'case', 'return', 'pending_return'] as const;
export const supportParentType = defineEnum({
  name: 'support_parent_type',
  values: SUPPORT_PARENT_TYPE,
  labels: labelsFor(SUPPORT_PARENT_TYPE),
});
export type SupportParentType = (typeof SUPPORT_PARENT_TYPE)[number];

export const RETURN_REASON = [
  'defective',
  'damaged_in_transit',
  'not_as_described',
  'wrong_item_received',
  'changed_mind',
  'wrong_size',
  'arrived_late',
  'other',
] as const;
export const returnReason = defineEnum({
  name: 'return_reason',
  values: RETURN_REASON,
  labels: labelsFor(RETURN_REASON),
});
export type ReturnReason = (typeof RETURN_REASON)[number];

export const RETURN_LIABILITY = ['vendor', 'buyer'] as const;
export const returnLiability = defineEnum({
  name: 'return_liability',
  values: RETURN_LIABILITY,
  labels: labelsFor(RETURN_LIABILITY),
});
export type ReturnLiability = (typeof RETURN_LIABILITY)[number];

export const SUPPORT_TICKET_CATEGORY = [
  'account',
  'billing',
  'bug',
  'how_to',
  'complaint',
  'other',
] as const;
export const supportTicketCategory = defineEnum({
  name: 'support_ticket_category',
  values: SUPPORT_TICKET_CATEGORY,
  labels: labelsFor(SUPPORT_TICKET_CATEGORY),
});
export type SupportTicketCategory = (typeof SUPPORT_TICKET_CATEGORY)[number];

export const SUPPORT_TICKET_STATUS = [
  'open',
  'ai_handling',
  'awaiting_user',
  'escalated',
  'awaiting_agent',
  'human_handling',
  'resolved',
  'closed',
  'reopened',
] as const;
export const supportTicketStatus = defineEnum({
  name: 'support_ticket_status',
  values: SUPPORT_TICKET_STATUS,
  labels: labelsFor(SUPPORT_TICKET_STATUS),
});
export type SupportTicketStatus = (typeof SUPPORT_TICKET_STATUS)[number];

export const SUPPORT_PRIORITY = ['low', 'normal', 'high', 'urgent'] as const;
export const supportPriority = defineEnum({
  name: 'support_priority',
  values: SUPPORT_PRIORITY,
  labels: labelsFor(SUPPORT_PRIORITY),
});
export type SupportPriority = (typeof SUPPORT_PRIORITY)[number];

export const SUPPORT_CASE_CATEGORY = [
  'item_not_as_described',
  'no_show_vendor',
  'quality_issue',
  'cannot_redeem',
  'cancellation_request',
  'fraud',
  'safety',
  'other',
] as const;
export const supportCaseCategory = defineEnum({
  name: 'support_case_category',
  values: SUPPORT_CASE_CATEGORY,
  labels: labelsFor(SUPPORT_CASE_CATEGORY),
});
export type SupportCaseCategory = (typeof SUPPORT_CASE_CATEGORY)[number];

export const SUPPORT_CASE_STATUS = [
  'opened',
  'vendor_review',
  'vendor_offered',
  'escalated',
  'ai_handling',
  'awaiting_info',
  'human_review',
  'resolved',
  'closed',
  'reopened',
] as const;
export const supportCaseStatus = defineEnum({
  name: 'support_case_status',
  values: SUPPORT_CASE_STATUS,
  labels: labelsFor(SUPPORT_CASE_STATUS),
});
export type SupportCaseStatus = (typeof SUPPORT_CASE_STATUS)[number];

export const CASE_OFFER_OUTCOME = ['refund_full', 'refund_partial', 'replacement', 'deny'] as const;
export const caseOfferOutcome = defineEnum({
  name: 'case_offer_outcome',
  values: CASE_OFFER_OUTCOME,
  labels: labelsFor(CASE_OFFER_OUTCOME),
});
export type CaseOfferOutcome = (typeof CASE_OFFER_OUTCOME)[number];

export const CASE_OFFER_BY = ['vendor', 'ai', 'human'] as const;
export const caseOfferBy = defineEnum({
  name: 'case_offer_by',
  values: CASE_OFFER_BY,
  labels: labelsFor(CASE_OFFER_BY),
});
export type CaseOfferBy = (typeof CASE_OFFER_BY)[number];

export const CASE_OFFER_STATUS = [
  'pending',
  'accepted',
  'rejected',
  'superseded',
  'auto_executed',
] as const;
export const caseOfferStatus = defineEnum({
  name: 'case_offer_status',
  values: CASE_OFFER_STATUS,
  labels: labelsFor(CASE_OFFER_STATUS),
});
export type CaseOfferStatus = (typeof CASE_OFFER_STATUS)[number];

export const CASE_RESOLUTION_EXECUTOR = [
  'vendor_auto',
  'customer_accept',
  'ai_auto',
  'human',
] as const;
export const caseResolutionExecutor = defineEnum({
  name: 'case_resolution_executor',
  values: CASE_RESOLUTION_EXECUTOR,
  labels: labelsFor(CASE_RESOLUTION_EXECUTOR),
});
export type CaseResolutionExecutor = (typeof CASE_RESOLUTION_EXECUTOR)[number];

export const SUPPORT_MESSAGE_AUTHOR_TYPE = [
  'customer',
  'vendor',
  'ai',
  'human_agent',
  'system',
  'admin',
] as const;
export const supportMessageAuthorType = defineEnum({
  name: 'support_message_author_type',
  values: SUPPORT_MESSAGE_AUTHOR_TYPE,
  labels: labelsFor(SUPPORT_MESSAGE_AUTHOR_TYPE),
});
export type SupportMessageAuthorType = (typeof SUPPORT_MESSAGE_AUTHOR_TYPE)[number];

export const SUPPORT_MESSAGE_VISIBILITY = ['public', 'vendor_internal', 'site_internal'] as const;
export const supportMessageVisibility = defineEnum({
  name: 'support_message_visibility',
  values: SUPPORT_MESSAGE_VISIBILITY,
  labels: labelsFor(SUPPORT_MESSAGE_VISIBILITY),
});
export type SupportMessageVisibility = (typeof SUPPORT_MESSAGE_VISIBILITY)[number];

export const SUPPORT_ATTACHMENT_ABUSE_STATUS = ['pending', 'clean', 'flagged', 'rejected'] as const;
export const supportAttachmentAbuseStatus = defineEnum({
  name: 'support_attachment_abuse_status',
  values: SUPPORT_ATTACHMENT_ABUSE_STATUS,
  labels: labelsFor(SUPPORT_ATTACHMENT_ABUSE_STATUS),
});
export type SupportAttachmentAbuseStatus = (typeof SUPPORT_ATTACHMENT_ABUSE_STATUS)[number];

export const AI_INTERVENTION_DECISION = ['auto', 'escalate', 'ask', 'propose'] as const;
export const aiInterventionDecision = defineEnum({
  name: 'ai_intervention_decision',
  values: AI_INTERVENTION_DECISION,
  labels: labelsFor(AI_INTERVENTION_DECISION),
});
export type AiInterventionDecision = (typeof AI_INTERVENTION_DECISION)[number];

export const SUPPORT_KB_CATEGORY = [
  'faq',
  'policy',
  'refund_rules',
  'redemption_rules',
  'internal',
] as const;
export const supportKbCategory = defineEnum({
  name: 'support_kb_category',
  values: SUPPORT_KB_CATEGORY,
  labels: labelsFor(SUPPORT_KB_CATEGORY),
});
export type SupportKbCategory = (typeof SUPPORT_KB_CATEGORY)[number];

export const SUPPORT_KB_VISIBILITY = ['public', 'internal'] as const;
export const supportKbVisibility = defineEnum({
  name: 'support_kb_visibility',
  values: SUPPORT_KB_VISIBILITY,
  labels: labelsFor(SUPPORT_KB_VISIBILITY),
});
export type SupportKbVisibility = (typeof SUPPORT_KB_VISIBILITY)[number];

export const EMAIL_VERIFICATION_PURPOSE = ['signup', 'change'] as const;
export const emailVerificationPurpose = defineEnum({
  name: 'email_verification_purpose',
  values: EMAIL_VERIFICATION_PURPOSE,
  labels: labelsFor(EMAIL_VERIFICATION_PURPOSE),
});
export type EmailVerificationPurpose = (typeof EMAIL_VERIFICATION_PURPOSE)[number];
