import 'package:cloud_firestore/cloud_firestore.dart';

class UserProfile {
  final String uid;
  final bool onboardingComplete;
  final String? persona;
  final String? energyBaseline;
  final String? decisionStyle;
  final List<String> focusAreas;
  final DateTime? createdAt;

  UserProfile({
    required this.uid,
    this.onboardingComplete = false,
    this.persona,
    this.energyBaseline,
    this.decisionStyle,
    this.focusAreas = const [],
    this.createdAt,
  });

  Map<String, dynamic> toMap() {
    return {
      'uid': uid,
      'onboardingComplete': onboardingComplete,
      'persona': persona,
      'energyBaseline': energyBaseline,
      'decisionStyle': decisionStyle,
      'focusAreas': focusAreas,
      'createdAt': createdAt != null
          ? Timestamp.fromDate(createdAt!)
          : FieldValue.serverTimestamp(),
    };
  }

  factory UserProfile.fromMap(Map<String, dynamic> map, String id) {
    return UserProfile(
      uid: id,
      onboardingComplete: map['onboardingComplete'] ?? false,
      persona: map['persona'],
      energyBaseline: map['energyBaseline'],
      decisionStyle: map['decisionStyle'],
      focusAreas: List<String>.from(map['focusAreas'] ?? []),
      createdAt: (map['createdAt'] as Timestamp?)?.toDate(),
    );
  }

  UserProfile copyWith({
    bool? onboardingComplete,
    String? persona,
    String? energyBaseline,
    String? decisionStyle,
    List<String>? focusAreas,
  }) {
    return UserProfile(
      uid: uid,
      onboardingComplete: onboardingComplete ?? this.onboardingComplete,
      persona: persona ?? this.persona,
      energyBaseline: energyBaseline ?? this.energyBaseline,
      decisionStyle: decisionStyle ?? this.decisionStyle,
      focusAreas: focusAreas ?? this.focusAreas,
      createdAt: createdAt,
    );
  }
}
