import 'package:cashier_reserve/common/base/ui_model.dart';
import 'package:cashier_reserve/common/channel/call_log_model.dart';
import 'package:cashier_reserve/common/channel/channel_manager.dart';
import 'package:cashier_reserve/common/manager/event_manager.dart';
import 'package:cashier_reserve/common/print/print.dart';

class ReserveViewModel extends BaseUIModel {
  Map<int, String> weekdayMap = {
    1: "星期一",
    2: "星期二",
    3: "星期三",
    4: "星期四",
    5: "星期五",
    6: "星期六",
    7: "星期日",
  };

  Map<int, String> dayInfoMap = {
    0: "今",
    1: "明",
    2: "后",
  };

  List<CallLogModel?>? callLogs = [];
  
  ReserveViewModel() {
    EventManager.addListener<GetCallLogEvent>(this, (event) {
      if (event.isSuccess) {
        if (!event.isSuccess) {
          return;
        }
        callLogs = event.callLogs;
        notifyListeners();
      }
    });

    loadCallLog();
  }
  
  void loadCallLog() {
    ChannelManager.getCallLog("getCallLog");
  }

  String getCurrentDate() {
    DateTime now = DateTime.now();
    return "${now.year}/${now.month}/${now.day}";
  }

  String getOffsetDay(int offset) {
    DateTime now = DateTime.now();
    DateTime offsetDay = now.add(Duration(days: offset));
    return "${dayInfoMap[offset]}/${offsetDay.day}";
  }

  String getOffsetWeekday(int offset) {
    DateTime now = DateTime.now();
    DateTime offsetDay = now.add(Duration(days: offset));
    return weekdayMap[offsetDay.weekday] ?? "";
  }
}