/**
 * Database Types for Monaco USA Portal 2026
 * Generated based on the architecture plan schema
 */

export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[];

export type Database = {
	public: {
		Tables: {
			members: {
				Row: {
					id: string;
					member_id: string;
					first_name: string;
					last_name: string;
					email: string;
					phone: string;
					date_of_birth: string;
					address: string;
					nationality: string[];
					role: 'member' | 'board' | 'admin';
					membership_status_id: string | null;
					membership_type_id: string | null;
					member_since: string;
					avatar_url: string | null;
					notes: string | null;
					directory_privacy: { show_email: boolean; show_phone: boolean; show_address: boolean; show_nationality: boolean } | null;
					created_at: string;
					updated_at: string;
				};
				Insert: {
					id: string;
					member_id?: string;
					first_name: string;
					last_name: string;
					email: string;
					phone: string;
					date_of_birth: string;
					address: string;
					nationality: string[];
					role?: 'member' | 'board' | 'admin';
					membership_status_id?: string | null;
					membership_type_id?: string | null;
					member_since?: string;
					avatar_url?: string | null;
					notes?: string | null;
					directory_privacy?: { show_email: boolean; show_phone: boolean; show_address: boolean; show_nationality: boolean } | null;
					created_at?: string;
					updated_at?: string;
				};
				Update: {
					id?: string;
					member_id?: string;
					first_name?: string;
					last_name?: string;
					email?: string;
					phone?: string;
					date_of_birth?: string;
					address?: string;
					nationality?: string[];
					role?: 'member' | 'board' | 'admin';
					membership_status_id?: string | null;
					membership_type_id?: string | null;
					member_since?: string;
					avatar_url?: string | null;
					notes?: string | null;
					directory_privacy?: { show_email: boolean; show_phone: boolean; show_address: boolean; show_nationality: boolean } | null;
					created_at?: string;
					updated_at?: string;
				};
			};
			membership_statuses: {
				Row: {
					id: string;
					name: string;
					display_name: string;
					color: string;
					description: string | null;
					is_default: boolean;
					sort_order: number;
					created_at: string;
				};
				Insert: {
					id?: string;
					name: string;
					display_name: string;
					color?: string;
					description?: string | null;
					is_default?: boolean;
					sort_order?: number;
					created_at?: string;
				};
				Update: {
					id?: string;
					name?: string;
					display_name?: string;
					color?: string;
					description?: string | null;
					is_default?: boolean;
					sort_order?: number;
					created_at?: string;
				};
			};
			membership_types: {
				Row: {
					id: string;
					name: string;
					display_name: string;
					annual_dues: number;
					description: string | null;
					is_default: boolean;
					is_active: boolean;
					sort_order: number;
					created_at: string;
				};
				Insert: {
					id?: string;
					name: string;
					display_name: string;
					annual_dues: number;
					description?: string | null;
					is_default?: boolean;
					is_active?: boolean;
					sort_order?: number;
					created_at?: string;
				};
				Update: {
					id?: string;
					name?: string;
					display_name?: string;
					annual_dues?: number;
					description?: string | null;
					is_default?: boolean;
					is_active?: boolean;
					sort_order?: number;
					created_at?: string;
				};
			};
			dues_payments: {
				Row: {
					id: string;
					member_id: string;
					amount: number;
					currency: string;
					payment_date: string;
					due_date: string;
					payment_method: string;
					reference: string | null;
					notes: string | null;
					recorded_by: string;
					created_at: string;
				};
				Insert: {
					id?: string;
					member_id: string;
					amount: number;
					currency?: string;
					payment_date: string;
					due_date?: string;
					payment_method?: string;
					reference?: string | null;
					notes?: string | null;
					recorded_by: string;
					created_at?: string;
				};
				Update: {
					id?: string;
					member_id?: string;
					amount?: number;
					currency?: string;
					payment_date?: string;
					due_date?: string;
					payment_method?: string;
					reference?: string | null;
					notes?: string | null;
					recorded_by?: string;
					created_at?: string;
				};
			};
			events: {
				Row: {
					id: string;
					title: string;
					description: string | null;
					event_type_id: string | null;
					start_datetime: string;
					end_datetime: string;
					all_day: boolean;
					timezone: string;
					location: string | null;
					location_url: string | null;
					max_attendees: number | null;
					max_guests_per_member: number;
					is_paid: boolean;
					member_price: number;
					non_member_price: number;
					pricing_notes: string | null;
					visibility: 'public' | 'members' | 'board' | 'admin';
					status: 'draft' | 'published' | 'cancelled' | 'completed';
					cover_image_url: string | null;
					created_by: string;
					created_at: string;
					updated_at: string;
				};
				Insert: {
					id?: string;
					title: string;
					description?: string | null;
					event_type_id?: string | null;
					start_datetime: string;
					end_datetime: string;
					all_day?: boolean;
					timezone?: string;
					location?: string | null;
					location_url?: string | null;
					max_attendees?: number | null;
					max_guests_per_member?: number;
					is_paid?: boolean;
					member_price?: number;
					non_member_price?: number;
					pricing_notes?: string | null;
					visibility?: 'public' | 'members' | 'board' | 'admin';
					status?: 'draft' | 'published' | 'cancelled' | 'completed';
					cover_image_url?: string | null;
					created_by: string;
					created_at?: string;
					updated_at?: string;
				};
				Update: {
					id?: string;
					title?: string;
					description?: string | null;
					event_type_id?: string | null;
					start_datetime?: string;
					end_datetime?: string;
					all_day?: boolean;
					timezone?: string;
					location?: string | null;
					location_url?: string | null;
					max_attendees?: number | null;
					max_guests_per_member?: number;
					is_paid?: boolean;
					member_price?: number;
					non_member_price?: number;
					pricing_notes?: string | null;
					visibility?: 'public' | 'members' | 'board' | 'admin';
					status?: 'draft' | 'published' | 'cancelled' | 'completed';
					cover_image_url?: string | null;
					created_by?: string;
					created_at?: string;
					updated_at?: string;
				};
			};
			event_types: {
				Row: {
					id: string;
					name: string;
					display_name: string;
					color: string;
					icon: string | null;
					description: string | null;
					is_active: boolean;
					sort_order: number;
					created_at: string;
				};
				Insert: {
					id?: string;
					name: string;
					display_name: string;
					color?: string;
					icon?: string | null;
					description?: string | null;
					is_active?: boolean;
					sort_order?: number;
					created_at?: string;
				};
				Update: {
					id?: string;
					name?: string;
					display_name?: string;
					color?: string;
					icon?: string | null;
					description?: string | null;
					is_active?: boolean;
					sort_order?: number;
					created_at?: string;
				};
			};
			event_rsvps: {
				Row: {
					id: string;
					event_id: string;
					member_id: string;
					status: 'confirmed' | 'declined' | 'maybe' | 'waitlist' | 'cancelled';
					guest_count: number;
					guest_names: string[] | null;
					notes: string | null;
					payment_status: 'not_required' | 'pending' | 'paid';
					payment_reference: string | null;
					payment_amount: number | null;
					attended: boolean;
					checked_in_at: string | null;
					checked_in_by: string | null;
					created_at: string;
					updated_at: string;
				};
				Insert: {
					id?: string;
					event_id: string;
					member_id: string;
					status?: 'confirmed' | 'declined' | 'maybe' | 'waitlist' | 'cancelled';
					guest_count?: number;
					guest_names?: string[] | null;
					notes?: string | null;
					payment_status?: 'not_required' | 'pending' | 'paid';
					payment_reference?: string | null;
					payment_amount?: number | null;
					attended?: boolean;
					checked_in_at?: string | null;
					checked_in_by?: string | null;
					created_at?: string;
					updated_at?: string;
				};
				Update: {
					id?: string;
					event_id?: string;
					member_id?: string;
					status?: 'confirmed' | 'declined' | 'maybe' | 'waitlist' | 'cancelled';
					guest_count?: number;
					guest_names?: string[] | null;
					notes?: string | null;
					payment_status?: 'not_required' | 'pending' | 'paid';
					payment_reference?: string | null;
					payment_amount?: number | null;
					attended?: boolean;
					checked_in_at?: string | null;
					checked_in_by?: string | null;
					created_at?: string;
					updated_at?: string;
				};
			};
			event_rsvps_public: {
				Row: {
					id: string;
					event_id: string;
					full_name: string;
					email: string;
					phone: string | null;
					status: 'confirmed' | 'declined' | 'maybe' | 'waitlist' | 'cancelled';
					guest_count: number;
					guest_names: string[] | null;
					payment_status: 'not_required' | 'pending' | 'paid';
					payment_reference: string | null;
					payment_amount: number | null;
					attended: boolean;
					created_at: string;
					updated_at: string;
				};
				Insert: {
					id?: string;
					event_id: string;
					full_name: string;
					email: string;
					phone?: string | null;
					status?: 'confirmed' | 'declined' | 'maybe' | 'waitlist' | 'cancelled';
					guest_count?: number;
					guest_names?: string[] | null;
					payment_status?: 'not_required' | 'pending' | 'paid';
					payment_reference?: string | null;
					payment_amount?: number | null;
					attended?: boolean;
					created_at?: string;
					updated_at?: string;
				};
				Update: {
					id?: string;
					event_id?: string;
					full_name?: string;
					email?: string;
					phone?: string | null;
					status?: 'confirmed' | 'declined' | 'maybe' | 'waitlist' | 'cancelled';
					guest_count?: number;
					guest_names?: string[] | null;
					payment_status?: 'not_required' | 'pending' | 'paid';
					payment_reference?: string | null;
					payment_amount?: number | null;
					attended?: boolean;
					created_at?: string;
					updated_at?: string;
				};
			};
			documents: {
				Row: {
					id: string;
					title: string;
					description: string | null;
					category_id: string | null;
					file_path: string;
					file_name: string;
					file_size: number;
					mime_type: string;
					visibility: 'public' | 'members' | 'board' | 'admin';
					allowed_member_ids: string[] | null;
					version: number;
					replaces_document_id: string | null;
					meeting_date: string | null;
					meeting_attendees: string[] | null;
					uploaded_by: string;
					created_at: string;
					updated_at: string;
				};
				Insert: {
					id?: string;
					title: string;
					description?: string | null;
					category_id?: string | null;
					file_path: string;
					file_name: string;
					file_size: number;
					mime_type: string;
					visibility?: 'public' | 'members' | 'board' | 'admin';
					allowed_member_ids?: string[] | null;
					version?: number;
					replaces_document_id?: string | null;
					meeting_date?: string | null;
					meeting_attendees?: string[] | null;
					uploaded_by: string;
					created_at?: string;
					updated_at?: string;
				};
				Update: {
					id?: string;
					title?: string;
					description?: string | null;
					category_id?: string | null;
					file_path?: string;
					file_name?: string;
					file_size?: number;
					mime_type?: string;
					visibility?: 'public' | 'members' | 'board' | 'admin';
					allowed_member_ids?: string[] | null;
					version?: number;
					replaces_document_id?: string | null;
					meeting_date?: string | null;
					meeting_attendees?: string[] | null;
					uploaded_by?: string;
					created_at?: string;
					updated_at?: string;
				};
			};
			document_categories: {
				Row: {
					id: string;
					name: string;
					display_name: string;
					description: string | null;
					icon: string | null;
					sort_order: number;
					is_active: boolean;
					created_at: string;
				};
				Insert: {
					id?: string;
					name: string;
					display_name: string;
					description?: string | null;
					icon?: string | null;
					sort_order?: number;
					is_active?: boolean;
					created_at?: string;
				};
				Update: {
					id?: string;
					name?: string;
					display_name?: string;
					description?: string | null;
					icon?: string | null;
					sort_order?: number;
					is_active?: boolean;
					created_at?: string;
				};
			};
			app_settings: {
				Row: {
					id: string;
					category: string;
					setting_key: string;
					setting_value: Json;
					setting_type: 'text' | 'number' | 'boolean' | 'json' | 'array';
					display_name: string;
					description: string | null;
					is_public: boolean;
					updated_at: string;
					updated_by: string | null;
				};
				Insert: {
					id?: string;
					category: string;
					setting_key: string;
					setting_value: Json;
					setting_type?: 'text' | 'number' | 'boolean' | 'json' | 'array';
					display_name: string;
					description?: string | null;
					is_public?: boolean;
					updated_at?: string;
					updated_by?: string | null;
				};
				Update: {
					id?: string;
					category?: string;
					setting_key?: string;
					setting_value?: Json;
					setting_type?: 'text' | 'number' | 'boolean' | 'json' | 'array';
					display_name?: string;
					description?: string | null;
					is_public?: boolean;
					updated_at?: string;
					updated_by?: string | null;
				};
			};
			email_templates: {
				Row: {
					id: string;
					template_key: string;
					template_name: string;
					category: string;
					subject: string;
					body_html: string;
					body_text: string | null;
					is_active: boolean;
					is_system: boolean;
					variables_schema: Json | null;
					preview_data: Json | null;
					created_at: string;
					updated_at: string;
					updated_by: string | null;
				};
				Insert: {
					id?: string;
					template_key: string;
					template_name: string;
					category: string;
					subject: string;
					body_html: string;
					body_text?: string | null;
					is_active?: boolean;
					is_system?: boolean;
					variables_schema?: Json | null;
					preview_data?: Json | null;
					created_at?: string;
					updated_at?: string;
					updated_by?: string | null;
				};
				Update: {
					id?: string;
					template_key?: string;
					template_name?: string;
					category?: string;
					subject?: string;
					body_html?: string;
					body_text?: string | null;
					is_active?: boolean;
					is_system?: boolean;
					variables_schema?: Json | null;
					preview_data?: Json | null;
					created_at?: string;
					updated_at?: string;
					updated_by?: string | null;
				};
			};
			email_logs: {
				Row: {
					id: string;
					recipient_id: string | null;
					recipient_email: string;
					recipient_name: string | null;
					template_key: string | null;
					subject: string;
					email_type: string;
					status: 'queued' | 'sent' | 'delivered' | 'opened' | 'clicked' | 'bounced' | 'failed';
					provider: string | null;
					provider_message_id: string | null;
					opened_at: string | null;
					clicked_at: string | null;
					error_message: string | null;
					retry_count: number;
					template_variables: Json | null;
					sent_by: string | null;
					created_at: string;
					sent_at: string | null;
					delivered_at: string | null;
				};
				Insert: {
					id?: string;
					recipient_id?: string | null;
					recipient_email: string;
					recipient_name?: string | null;
					template_key?: string | null;
					subject: string;
					email_type: string;
					status?: 'queued' | 'sent' | 'delivered' | 'opened' | 'clicked' | 'bounced' | 'failed';
					provider?: string | null;
					provider_message_id?: string | null;
					opened_at?: string | null;
					clicked_at?: string | null;
					error_message?: string | null;
					retry_count?: number;
					template_variables?: Json | null;
					sent_by?: string | null;
					created_at?: string;
					sent_at?: string | null;
					delivered_at?: string | null;
				};
				Update: {
					id?: string;
					recipient_id?: string | null;
					recipient_email?: string;
					recipient_name?: string | null;
					template_key?: string | null;
					subject?: string;
					email_type?: string;
					status?: 'queued' | 'sent' | 'delivered' | 'opened' | 'clicked' | 'bounced' | 'failed';
					provider?: string | null;
					provider_message_id?: string | null;
					opened_at?: string | null;
					clicked_at?: string | null;
					error_message?: string | null;
					retry_count?: number;
					template_variables?: Json | null;
					sent_by?: string | null;
					created_at?: string;
					sent_at?: string | null;
					delivered_at?: string | null;
				};
			};
			audit_logs: {
				Row: {
					id: string;
					user_id: string | null;
					user_email: string | null;
					action: string;
					resource_type: string | null;
					resource_id: string | null;
					details: Json;
					ip_address: string | null;
					user_agent: string | null;
					created_at: string;
				};
				Insert: {
					id?: string;
					user_id?: string | null;
					user_email?: string | null;
					action: string;
					resource_type?: string | null;
					resource_id?: string | null;
					details?: Json;
					ip_address?: string | null;
					user_agent?: string | null;
					created_at?: string;
				};
				Update: {
					id?: string;
					user_id?: string | null;
					user_email?: string | null;
					action?: string;
					resource_type?: string | null;
					resource_id?: string | null;
					details?: Json;
					ip_address?: string | null;
					user_agent?: string | null;
					created_at?: string;
				};
			};
			dues_reminder_logs: {
				Row: {
					id: string;
					member_id: string;
					reminder_type: 'due_soon_30' | 'due_soon_7' | 'due_soon_1' | 'overdue' | 'grace_period' | 'inactive_notice';
					due_date: string;
					sent_at: string;
					email_log_id: string | null;
				};
				Insert: {
					id?: string;
					member_id: string;
					reminder_type: 'due_soon_30' | 'due_soon_7' | 'due_soon_1' | 'overdue' | 'grace_period' | 'inactive_notice';
					due_date: string;
					sent_at?: string;
					email_log_id?: string | null;
				};
				Update: {
					id?: string;
					member_id?: string;
					reminder_type?: 'due_soon_30' | 'due_soon_7' | 'due_soon_1' | 'overdue' | 'grace_period' | 'inactive_notice';
					due_date?: string;
					sent_at?: string;
					email_log_id?: string | null;
				};
			};
		};
		Views: {
			members_with_dues: {
				Row: {
					id: string;
					member_id: string;
					first_name: string;
					last_name: string;
					email: string;
					phone: string;
					date_of_birth: string;
					address: string;
					nationality: string[];
					role: 'member' | 'board' | 'admin';
					membership_status_id: string | null;
					membership_type_id: string | null;
					member_since: string;
					avatar_url: string | null;
					notes: string | null;
					created_at: string;
					updated_at: string;
					status_name: string | null;
					status_display_name: string | null;
					status_color: string | null;
					membership_type_name: string | null;
					annual_dues: number | null;
					last_payment_date: string | null;
					current_due_date: string | null;
					dues_status: 'never_paid' | 'overdue' | 'due_soon' | 'current';
					days_overdue: number | null;
					days_until_due: number | null;
				};
			};
			events_with_counts: {
				Row: {
					id: string;
					title: string;
					description: string | null;
					event_type_id: string | null;
					start_datetime: string;
					end_datetime: string;
					all_day: boolean;
					timezone: string;
					location: string | null;
					location_url: string | null;
					max_attendees: number | null;
					max_guests_per_member: number;
					is_paid: boolean;
					member_price: number;
					non_member_price: number;
					pricing_notes: string | null;
					visibility: 'public' | 'members' | 'board' | 'admin';
					status: 'draft' | 'published' | 'cancelled' | 'completed';
					cover_image_url: string | null;
					created_by: string;
					created_at: string;
					updated_at: string;
					event_type_name: string | null;
					event_type_color: string | null;
					event_type_icon: string | null;
					total_attendees: number;
					member_count: number;
					non_member_count: number;
					waitlist_count: number;
					is_full: boolean;
				};
			};
		};
		Functions: Record<string, never>;
		Enums: Record<string, never>;
	};
};

// Convenience types
export type Member = Database['public']['Tables']['members']['Row'];
export type MemberInsert = Database['public']['Tables']['members']['Insert'];
export type MemberUpdate = Database['public']['Tables']['members']['Update'];

export type MemberWithDues = Database['public']['Views']['members_with_dues']['Row'];

export type Event = Database['public']['Tables']['events']['Row'];
export type EventInsert = Database['public']['Tables']['events']['Insert'];
export type EventUpdate = Database['public']['Tables']['events']['Update'];

export type EventWithCounts = Database['public']['Views']['events_with_counts']['Row'];

export type EventRSVP = Database['public']['Tables']['event_rsvps']['Row'];
export type EventRSVPInsert = Database['public']['Tables']['event_rsvps']['Insert'];

export type DuesPayment = Database['public']['Tables']['dues_payments']['Row'];
export type DuesPaymentInsert = Database['public']['Tables']['dues_payments']['Insert'];

export type Document = Database['public']['Tables']['documents']['Row'];
export type DocumentInsert = Database['public']['Tables']['documents']['Insert'];

export type AppSetting = Database['public']['Tables']['app_settings']['Row'];
export type EmailTemplate = Database['public']['Tables']['email_templates']['Row'];
export type EmailLog = Database['public']['Tables']['email_logs']['Row'];
export type AuditLog = Database['public']['Tables']['audit_logs']['Row'];
export type DuesReminderLog = Database['public']['Tables']['dues_reminder_logs']['Row'];

// Role type
export type MemberRole = 'member' | 'board' | 'admin';

// Event visibility
export type EventVisibility = 'public' | 'members' | 'board' | 'admin';

// Dues status
export type DuesStatus = 'never_paid' | 'overdue' | 'due_soon' | 'current';
