export class User {
  id?: string;
  username: string;
  email: string;
  firstName: string;
  lastName: string;
  enabled?: boolean;
  emailVerified?: boolean;
  attributes?: { [key: string]: any };
  createdTimestamp?: number;
  
  constructor(partial?: Partial<User>) {
    // Initialisation des propriétés obligatoires
    this.username = '';
    this.email = '';
    this.firstName = '';
    this.lastName = '';
    
    if (partial) {
      Object.assign(this, partial);
    }
    
    // Valeurs par défaut
    this.enabled = this.enabled ?? true;
    this.emailVerified = this.emailVerified ?? false;
  }
}

export class UserResponse {
  id: string;
  username: string;
  email: string;
  firstName: string;
  lastName: string;
  enabled: boolean;
  emailVerified: boolean;
  attributes?: { [key: string]: any };
  clientRoles: string[];
  createdTimestamp: number;

  constructor(user: any) {
    // Initialisation avec valeurs par défaut
    this.id = user?.id || '';
    this.username = user?.username || '';
    this.email = user?.email || '';
    this.firstName = user?.firstName || '';
    this.lastName = user?.lastName || '';
    this.enabled = user?.enabled ?? true;
    this.emailVerified = user?.emailVerified ?? false;
    this.attributes = user?.attributes || {};
    this.clientRoles = user?.clientRoles || [];
    this.createdTimestamp = user?.createdTimestamp || Date.now();
  }
}

export class CreateUserDto {
  username: string = '';
  email: string = '';
  firstName: string = '';
  lastName: string = '';
  password: string = '';
  enabled: boolean = true;
  emailVerified: boolean = false;
  clientRoles: string[] = [];

  constructor(partial?: Partial<CreateUserDto>) {
    if (partial) {
      Object.assign(this, partial);
    }
  }
}

export class UpdateUserDto {
  username?: string;
  email?: string;
  firstName?: string;
  lastName?: string;
  enabled?: boolean;
  emailVerified?: boolean;
  attributes?: { [key: string]: any };

  constructor(partial?: Partial<UpdateUserDto>) {
    if (partial) {
      Object.assign(this, partial);
    }
  }
}

export class ResetPasswordDto {
  userId: string;
  newPassword: string;
  temporary?: boolean;

  constructor(partial?: Partial<ResetPasswordDto>) {
    // Initialisation des propriétés obligatoires
    this.userId = '';
    this.newPassword = '';
    
    if (partial) {
      Object.assign(this, partial);
    }
    
    // Valeur par défaut
    this.temporary = this.temporary ?? false;
  }
}

export class UserQueryDto {
  page?: number;
  limit?: number;
  search?: string;
  enabled?: boolean;
  emailVerified?: boolean; // 🔥 Ajouter ce champ
  email?: string;
  username?: string;
  firstName?: string;
  lastName?: string;

  constructor(partial?: Partial<UserQueryDto>) {
    if (partial) {
      Object.assign(this, partial);
    }
  }
}

export class PaginatedUserResponse {
  data: UserResponse[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;

  constructor(data: UserResponse[], total: number, page: number, limit: number) {
    this.data = data || [];
    this.total = total || 0;
    this.page = page || 1;
    this.limit = limit || 10;
    this.totalPages = Math.ceil(this.total / this.limit);
  }
}

export class UserCredentials {
  type: string;
  value: string;
  temporary: boolean;

  constructor(type: string, value: string, temporary: boolean = false) {
    this.type = type;
    this.value = value;
    this.temporary = temporary;
  }
}

// Types (restent des interfaces/type alias)
export type ClientRole = 'admin' | 'merchant' | 'support' | 'user';

export interface ApiResponse<T> {
  data: T;
  message?: string;
  status: string;
}

export interface UserRoleMapping {
  id: string;
  name: string;
  description?: string;
  composite?: boolean;
  clientRole?: boolean;
  containerId?: string;
}

export interface UserSession {
  id: string;
  username: string;
  userId: string;
  ipAddress: string;
  start: number;
  lastAccess: number;
  clients: { [key: string]: string };
}