import 'package:widgets/load_state_layout.dart';

class ForsaleState {
  int? activeTabIndex =0;
  //页面 LoadView 状态的展示
  LoadState loadingState;
  String? errorMessage;

  String? keyword;
  bool? isLiked;
  List<Map<String, dynamic>> list;


  ForsaleState({
    this.activeTabIndex,
    this.loadingState = LoadState.State_Loading,
    String? errorMessage,
    this.keyword,
    this.isLiked,
    required this.list,
  });

  ForsaleState copyWith({
    int? activeTabIndex,
    LoadState? loadingState,
    String? errorMessage,
    String? keyword,
    bool? isLiked,
    List<Map<String, dynamic>>? list,
  }) {
    return ForsaleState(
      activeTabIndex: activeTabIndex ?? this.activeTabIndex,
      loadingState: loadingState ?? this.loadingState,
      errorMessage: errorMessage ?? this.errorMessage,
      keyword: keyword ?? this.keyword,
      isLiked: isLiked ?? this.isLiked,
      list: list ?? this.list,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'activeTabIndex': this.activeTabIndex,
      'loadingState': this.loadingState,
      'errorMessage': this.errorMessage,
      'keyword': this.keyword,
      'isLiked': this.isLiked,
      'list': this.list,
    };
  }

  factory ForsaleState.fromMap(Map<String, dynamic> map) {
    return ForsaleState(
      activeTabIndex: map['activeTabIndex'] as int,
      loadingState: map['loadingState'] as LoadState,
      errorMessage: map['errorMessage'] as String,
      keyword: map['keyword'] as String,
      isLiked: map['isLiked'] as bool,
      list: map['list'] as List<Map<String, dynamic>>,
    );
  }
}