import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:marking_app/common/model/job/job_page_tab.dart';

part 'job_do_synchro_tab.g.dart';

@JsonSerializable()
class JobDoSynchroTab extends Object {
  List<JobPageTab> tabs;

  JobDoSynchroTab(this.tabs);

  factory JobDoSynchroTab.fromJson(Map<String, dynamic> srcJson) => _$JobDoSynchroTabFromJson(srcJson);

  Map<String, dynamic> toJson() => _$JobDoSynchroTabToJson(this);

  /// 当前tab下一个tab的pageIndex
  int? getNextPageIndex([int? pageIndex]) {
    if (pageIndex == null) return null;
    var _index = tabs.indexWhere((e) => e.pageIndex == pageIndex);
    if (_index == -1) return null;

    return _index == tabs.length - 1 ? null : tabs[_index + 1].pageIndex;
  }

  /// 当前tab上一个tab的pageIndex
  int? getPreviousPageIndex([int? pageIndex]) {
    if (pageIndex == null) return null;
    var _index = tabs.indexWhere((e) => e.pageIndex == pageIndex);
    if (_index == -1) return null;
    pageIndex = _index == 0 ? null : tabs[_index - 1].pageIndex;
    print('这是上一页的数据：${pageIndex}');
    return pageIndex;
  }
}
