// utils/types.ts
export interface User {
  id: string;
  email: string;
  name: string;
  firstName?: string;
  lastName?: string;
  username?: string;
  tier: 'user' | 'board' | 'admin';
  groups: string[];
}

export interface AuthState {
  authenticated: boolean;
  user: User | null;
  groups: string[];
}

export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  error?: string;
  message?: string;
}

export interface FileUpload {
  fieldName: string;
  fileName: string;
  originalName: string;
  size: number;
  contentType: string;
}

export interface DatabaseRecord {
  id: string;
  created_at: string;
  updated_at: string;
  [key: string]: any;
}

export interface HealthCheck {
  status: 'healthy' | 'degraded' | 'unhealthy';
  timestamp: string;
  checks: {
    server: string;
    database: string;
    storage: string;
    auth: string;
  };
}

export interface TokenResponse {
  access_token: string;
  refresh_token: string;
  id_token: string;
  token_type: string;
  expires_in: number;
}

export interface UserInfo {
  sub: string;
  email: string;
  given_name?: string;
  family_name?: string;
  name?: string;
  preferred_username?: string;
  groups?: string[];
  tier?: string;
}

export interface SessionData {
  user: User;
  tokens: {
    accessToken: string;
    refreshToken: string;
    expiresAt: number;
  };
  rememberMe?: boolean;
  createdAt: number;
  lastActivity: number;
}

export interface KeycloakConfig {
  issuer: string;
  clientId: string;
  clientSecret: string;
  callbackUrl: string;
}

export interface KeycloakAdminConfig {
  issuer: string;
  clientId: string;
  clientSecret: string;
}

export interface NocoDBConfig {
  url: string;
  token: string;
  baseId: string;
}

export interface MinIOConfig {
  endPoint: string;
  port: number;
  useSSL: boolean;
  accessKey: string;
  secretKey: string;
  bucketName: string;
}

// Member Management Types
export enum MembershipStatus {
  Active = 'Active',
  Inactive = 'Inactive',
  Pending = 'Pending',
  Expired = 'Expired'
}

export interface Member {
  Id: string;
  first_name: string;
  last_name: string;
  email: string;
  phone: string;
  current_year_dues_paid: string; // "true" or "false"
  nationality: string; // "FR,MC,US" for multiple nationalities
  date_of_birth: string;
  membership_date_paid: string;
  payment_due_date: string;
  membership_status: string;
  address: string;
  member_since: string;
  
  // Computed fields (added by processing)
  FullName?: string;
  FormattedPhone?: string;
  NationalityArray?: string[]; // Parsed from comma-separated string
}

// Admin-only NocoDB Configuration
export interface NocoDBSettings {
  url: string;
  apiKey: string;
  baseId: string;
  tables: { [tableName: string]: string }; // e.g., { "members": "m2sri3jqfqutiy5", "events": "evt123abc", ... }
}

export interface MemberResponse {
  list: Member[];
  PageInfo: {
    pageSize: number;
    totalRows: number;
    isFirstPage: boolean;
    isLastPage: boolean;
    page: number;
  };
}

export interface MemberFilters {
  searchTerm?: string;
  nationality?: string;
  membershipStatus?: MembershipStatus;
  duesPaid?: boolean;
  memberSince?: string;
}
