import 'package:flutter/foundation.dart';

import 'package:pshared/models/describable.dart';
import 'package:pshared/models/storable.dart';
import 'package:pshared/models/storable/describable.dart';
import 'package:pshared/utils/name_initials.dart';


@immutable
class AccountBase implements StorableDescribable {
  final Storable storable;
  final Describable describable;
  final String lastName;

  @override
  String get id => storable.id;
  @override
  DateTime get createdAt => storable.createdAt;
  @override
  DateTime get updatedAt => storable.updatedAt;
  @override
  String get name => describable.name;
  String get fullName {
    final first = describable.name.trim();
    final last = lastName.trim();

    if (last.isEmpty) return first;
    if (first.isEmpty) return last;
    return '$first $last';
  }
  @override
  String? get description => describable.description;

  final String? avatarUrl;

  const AccountBase({
    required this.storable,
    required this.describable,
    required this.avatarUrl,
    required this.lastName,
  });

  String get nameInitials => getNameInitials(fullName);

   AccountBase copyWith({
    Describable? describable,
    String? lastName,
    String? Function()? avatarUrl,
  }) => AccountBase(
    storable: storable,
    avatarUrl: avatarUrl != null ? avatarUrl() : this.avatarUrl,
    describable: describable ?? this.describable,
    lastName: lastName ?? this.lastName,
  );
}
