export interface EventType {
	value: string;
	label: string;
}

export interface EventTypeCategory {
	name: string;
	label: string;
	types: EventType[];
}

export const EVENT_TYPE_CATEGORIES: EventTypeCategory[] = [
	{
		name: 'customer',
		label: 'Customer',
		types: [
			{ value: 'CUSTOMER_CREATED', label: 'Customer Created' },
			{ value: 'CUSTOMER_UPDATED', label: 'Customer Updated' },
			{ value: 'CUSTOMER_DELETED', label: 'Customer Deleted' },
			{ value: 'CUSTOMER_STATUS_CHANGED', label: 'Customer Status Changed' },
			{ value: 'CUSTOMER_ADDRESS_CREATED', label: 'Customer Address Created' },
			{ value: 'CUSTOMER_ADDRESS_UPDATED', label: 'Customer Address Updated' },
			{ value: 'CUSTOMER_ADDRESS_DELETED', label: 'Customer Address Deleted' },
			{ value: 'CUSTOMER_CONTACT_CREATED', label: 'Customer Contact Created' },
			{ value: 'CUSTOMER_CONTACT_UPDATED', label: 'Customer Contact Updated' },
			{ value: 'CUSTOMER_CONTACT_DELETED', label: 'Customer Contact Deleted' }
		]
	},
	{
		name: 'account',
		label: 'Account',
		types: [
			{ value: 'ACCOUNT_CREATED', label: 'Account Created' },
			{ value: 'ACCOUNT_UPDATED', label: 'Account Updated' },
			{ value: 'ACCOUNT_DELETED', label: 'Account Deleted' },
			{ value: 'ACCOUNT_STATUS_CHANGED', label: 'Account Status Changed' },
			{ value: 'ACCOUNT_ADDRESS_CREATED', label: 'Account Address Created' },
			{ value: 'ACCOUNT_ADDRESS_UPDATED', label: 'Account Address Updated' },
			{ value: 'ACCOUNT_ADDRESS_DELETED', label: 'Account Address Deleted' },
			{ value: 'ACCOUNT_CONTACT_CREATED', label: 'Account Contact Created' },
			{ value: 'ACCOUNT_CONTACT_UPDATED', label: 'Account Contact Updated' },
			{ value: 'ACCOUNT_CONTACT_DELETED', label: 'Account Contact Deleted' }
		]
	},
	{
		name: 'service',
		label: 'Service',
		types: [
			{ value: 'SERVICE_CREATED', label: 'Service Created' },
			{ value: 'SERVICE_UPDATED', label: 'Service Updated' },
			{ value: 'SERVICE_DELETED', label: 'Service Deleted' },
			{ value: 'SERVICE_STATUS_CHANGED', label: 'Service Status Changed' },
			{ value: 'SERVICE_COMPLETED', label: 'Service Completed' },
			{ value: 'SERVICE_CANCELLED', label: 'Service Cancelled' },
			{ value: 'SERVICE_DISPATCHED', label: 'Service Dispatched' },
			{ value: 'SERVICE_TEAM_ASSIGNED', label: 'Team Assigned to Service' },
			{ value: 'SERVICE_TEAM_UNASSIGNED', label: 'Team Unassigned from Service' },
			{ value: 'SERVICES_BULK_GENERATED', label: 'Services Bulk Generated' }
		]
	},
	{
		name: 'service_session',
		label: 'Service Session',
		types: [
			{ value: 'SERVICE_SESSION_OPENED', label: 'Service Session Opened' },
			{ value: 'SERVICE_SESSION_CLOSED', label: 'Service Session Closed' },
			{ value: 'SERVICE_SESSION_REVERTED', label: 'Service Session Reverted' },
			{ value: 'SERVICE_TASK_COMPLETED', label: 'Service Task Completed' },
			{ value: 'SERVICE_TASK_UNCOMPLETED', label: 'Service Task Uncompleted' }
		]
	},
	{
		name: 'schedule',
		label: 'Schedule',
		types: [
			{ value: 'SCHEDULE_CREATED', label: 'Schedule Created' },
			{ value: 'SCHEDULE_UPDATED', label: 'Schedule Updated' },
			{ value: 'SCHEDULE_DELETED', label: 'Schedule Deleted' },
			{ value: 'SCHEDULE_FREQUENCY_CHANGED', label: 'Schedule Frequency Changed' }
		]
	},
	{
		name: 'project',
		label: 'Project',
		types: [
			{ value: 'PROJECT_CREATED', label: 'Project Created' },
			{ value: 'PROJECT_UPDATED', label: 'Project Updated' },
			{ value: 'PROJECT_STATUS_CHANGED', label: 'Project Status Changed' },
			{ value: 'PROJECT_COMPLETED', label: 'Project Completed' },
			{ value: 'PROJECT_CANCELLED', label: 'Project Cancelled' },
			{ value: 'PROJECT_DISPATCHED', label: 'Project Dispatched' }
		]
	},
	{
		name: 'project_session',
		label: 'Project Session',
		types: [
			{ value: 'PROJECT_SESSION_OPENED', label: 'Project Session Opened' },
			{ value: 'PROJECT_SESSION_CLOSED', label: 'Project Session Closed' },
			{ value: 'PROJECT_SESSION_REVERTED', label: 'Project Session Reverted' },
			{ value: 'PROJECT_TASK_COMPLETED', label: 'Project Task Completed' },
			{ value: 'PROJECT_TASK_UNCOMPLETED', label: 'Project Task Uncompleted' }
		]
	},
	{
		name: 'project_scope',
		label: 'Project Scope',
		types: [
			{ value: 'PROJECT_SCOPE_CREATED', label: 'Project Scope Created' },
			{ value: 'PROJECT_SCOPE_UPDATED', label: 'Project Scope Updated' },
			{ value: 'PROJECT_SCOPE_DELETED', label: 'Project Scope Deleted' },
			{ value: 'PROJECT_SCOPE_CATEGORY_CREATED', label: 'Project Scope Category Created' },
			{ value: 'PROJECT_SCOPE_CATEGORY_UPDATED', label: 'Project Scope Category Updated' },
			{ value: 'PROJECT_SCOPE_CATEGORY_DELETED', label: 'Project Scope Category Deleted' },
			{ value: 'PROJECT_SCOPE_TASK_CREATED', label: 'Project Scope Task Created' },
			{ value: 'PROJECT_SCOPE_TASK_UPDATED', label: 'Project Scope Task Updated' },
			{ value: 'PROJECT_SCOPE_TASK_DELETED', label: 'Project Scope Task Deleted' },
			{ value: 'PROJECT_SCOPE_TEMPLATE_INSTANTIATED', label: 'Project Scope Template Instantiated' }
		]
	},
	{
		name: 'scope',
		label: 'Scope',
		types: [
			{ value: 'SCOPE_CREATED', label: 'Scope Created' },
			{ value: 'SCOPE_UPDATED', label: 'Scope Updated' },
			{ value: 'SCOPE_DELETED', label: 'Scope Deleted' },
			{ value: 'AREA_CREATED', label: 'Area Created' },
			{ value: 'AREA_UPDATED', label: 'Area Updated' },
			{ value: 'AREA_DELETED', label: 'Area Deleted' },
			{ value: 'TASK_CREATED', label: 'Task Created' },
			{ value: 'TASK_UPDATED', label: 'Task Updated' },
			{ value: 'TASK_DELETED', label: 'Task Deleted' },
			{ value: 'TASK_COMPLETION_RECORDED', label: 'Task Completion Recorded' }
		]
	},
	{
		name: 'scope_template',
		label: 'Scope Template',
		types: [
			{ value: 'SCOPE_TEMPLATE_CREATED', label: 'Scope Template Created' },
			{ value: 'SCOPE_TEMPLATE_UPDATED', label: 'Scope Template Updated' },
			{ value: 'SCOPE_TEMPLATE_DELETED', label: 'Scope Template Deleted' },
			{ value: 'SCOPE_TEMPLATE_INSTANTIATED', label: 'Scope Template Instantiated' },
			{ value: 'AREA_TEMPLATE_CREATED', label: 'Area Template Created' },
			{ value: 'AREA_TEMPLATE_UPDATED', label: 'Area Template Updated' },
			{ value: 'AREA_TEMPLATE_DELETED', label: 'Area Template Deleted' },
			{ value: 'TASK_TEMPLATE_CREATED', label: 'Task Template Created' },
			{ value: 'TASK_TEMPLATE_UPDATED', label: 'Task Template Updated' },
			{ value: 'TASK_TEMPLATE_DELETED', label: 'Task Template Deleted' }
		]
	},
	{
		name: 'team_profile',
		label: 'Team Profile',
		types: [
			{ value: 'TEAM_PROFILE_CREATED', label: 'Team Profile Created' },
			{ value: 'TEAM_PROFILE_UPDATED', label: 'Team Profile Updated' },
			{ value: 'TEAM_PROFILE_DELETED', label: 'Team Profile Deleted' },
			{ value: 'TEAM_PROFILE_ROLE_CHANGED', label: 'Team Profile Role Changed' }
		]
	},
	{
		name: 'customer_profile',
		label: 'Customer Profile',
		types: [
			{ value: 'CUSTOMER_PROFILE_CREATED', label: 'Customer Profile Created' },
			{ value: 'CUSTOMER_PROFILE_UPDATED', label: 'Customer Profile Updated' },
			{ value: 'CUSTOMER_PROFILE_DELETED', label: 'Customer Profile Deleted' },
			{ value: 'CUSTOMER_PROFILE_ACCESS_GRANTED', label: 'Customer Profile Access Granted' },
			{ value: 'CUSTOMER_PROFILE_ACCESS_REVOKED', label: 'Customer Profile Access Revoked' }
		]
	},
	{
		name: 'punchlist',
		label: 'Punchlist',
		types: [
			{ value: 'ACCOUNT_PUNCHLIST_CREATED', label: 'Account Punchlist Created' },
			{ value: 'ACCOUNT_PUNCHLIST_UPDATED', label: 'Account Punchlist Updated' },
			{ value: 'ACCOUNT_PUNCHLIST_DELETED', label: 'Account Punchlist Deleted' },
			{ value: 'PROJECT_PUNCHLIST_CREATED', label: 'Project Punchlist Created' },
			{ value: 'PROJECT_PUNCHLIST_UPDATED', label: 'Project Punchlist Updated' },
			{ value: 'PROJECT_PUNCHLIST_DELETED', label: 'Project Punchlist Deleted' },
			{ value: 'PUNCHLIST_STATUS_CHANGED', label: 'Punchlist Status Changed' },
			{ value: 'PUNCHLIST_PRIORITY_CHANGED', label: 'Punchlist Priority Changed' }
		]
	},
	{
		name: 'media',
		label: 'Session Media',
		types: [
			{ value: 'SESSION_IMAGE_UPLOADED', label: 'Session Image Uploaded' },
			{ value: 'SESSION_IMAGE_UPDATED', label: 'Session Image Updated' },
			{ value: 'SESSION_IMAGE_DELETED', label: 'Session Image Deleted' },
			{ value: 'SESSION_VIDEO_UPLOADED', label: 'Session Video Uploaded' },
			{ value: 'SESSION_VIDEO_UPDATED', label: 'Session Video Updated' },
			{ value: 'SESSION_VIDEO_DELETED', label: 'Session Video Deleted' },
			{ value: 'SESSION_MEDIA_INTERNAL_FLAGGED', label: 'Session Media Flagged as Internal' }
		]
	},
	{
		name: 'notes',
		label: 'Session Notes',
		types: [
			{ value: 'SESSION_NOTE_CREATED', label: 'Session Note Created' },
			{ value: 'SESSION_NOTE_UPDATED', label: 'Session Note Updated' },
			{ value: 'SESSION_NOTE_DELETED', label: 'Session Note Deleted' }
		]
	},
	{
		name: 'report',
		label: 'Report',
		types: [
			{ value: 'REPORT_CREATED', label: 'Report Created' },
			{ value: 'REPORT_SUBMITTED', label: 'Report Submitted' },
			{ value: 'REPORT_APPROVED', label: 'Report Approved' }
		]
	},
	{
		name: 'invoice',
		label: 'Invoice',
		types: [
			{ value: 'INVOICE_GENERATED', label: 'Invoice Generated' },
			{ value: 'INVOICE_SENT', label: 'Invoice Sent' },
			{ value: 'INVOICE_PAID', label: 'Invoice Paid' },
			{ value: 'INVOICE_OVERDUE', label: 'Invoice Overdue' },
			{ value: 'INVOICE_CANCELLED', label: 'Invoice Cancelled' }
		]
	},
	{
		name: 'labor_revenue',
		label: 'Labor & Revenue',
		types: [
			{ value: 'LABOR_RATE_CREATED', label: 'Labor Rate Created' },
			{ value: 'LABOR_RATE_UPDATED', label: 'Labor Rate Updated' },
			{ value: 'LABOR_RATE_DELETED', label: 'Labor Rate Deleted' },
			{ value: 'REVENUE_RATE_CREATED', label: 'Revenue Rate Created' },
			{ value: 'REVENUE_RATE_UPDATED', label: 'Revenue Rate Updated' },
			{ value: 'REVENUE_RATE_DELETED', label: 'Revenue Rate Deleted' }
		]
	},
	{
		name: 'messaging',
		label: 'Messaging',
		types: [
			{ value: 'CONVERSATION_CREATED', label: 'Conversation Created' },
			{ value: 'CONVERSATION_ARCHIVED', label: 'Conversation Archived' },
			{ value: 'CONVERSATION_PARTICIPANT_ADDED', label: 'Participant Added to Conversation' },
			{ value: 'CONVERSATION_PARTICIPANT_REMOVED', label: 'Participant Removed from Conversation' },
			{ value: 'MESSAGE_SENT', label: 'Message Sent' },
			{ value: 'MESSAGE_RECEIVED', label: 'Message Received' },
			{ value: 'MESSAGE_READ', label: 'Message Read' },
			{ value: 'MESSAGE_DELETED', label: 'Message Deleted' }
		]
	},
	{
		name: 'monitoring',
		label: 'Monitoring',
		types: [
			{ value: 'MONITORING_COMMAND_EXECUTED', label: 'Monitoring Command Executed' },
			{ value: 'MONITORING_INCOMPLETE_WORK_REMINDER', label: 'Incomplete Work Reminder' },
			{ value: 'MONITORING_NIGHTLY_ASSIGNMENTS', label: 'Nightly Assignments' }
		]
	}
];

// Flat list of all event types for validation
export const ALL_EVENT_TYPES = EVENT_TYPE_CATEGORIES.flatMap((cat) =>
	cat.types.map((t) => t.value)
);

// Lookup map for quick label retrieval
export const EVENT_TYPE_LABELS: Record<string, string> = Object.fromEntries(
	EVENT_TYPE_CATEGORIES.flatMap((cat) => cat.types.map((t) => [t.value, t.label]))
);

// Get label for an event type
export function getEventTypeLabel(eventType: string): string {
	return (
		EVENT_TYPE_LABELS[eventType] ||
		eventType
			.replace(/_/g, ' ')
			.toLowerCase()
			.replace(/\b\w/g, (c) => c.toUpperCase())
	);
}
