import 'dart:typed_data';

import 'package:dio/dio.dart';

import '../about/external/data/Commitment.dart';
import '../about/external/data/Program.dart';
import '../about/external/data/SystemResponse.dart';
import '../about/external/data/pages/request/CommitmentsRequest.dart';
import '../about/external/data/pages/request/HistoryRequest.dart';
import '../about/external/initial/AbandonRequest.dart';
import '../about/external/initial/AmnestyRequest.dart';
import '../about/external/initial/CommitmentRequest.dart';
import '../about/external/initial/CompletionRequest.dart';
import '../about/external/initial/DeferralRequest.dart';
import '../about/external/initial/DeviceRequest.dart';
import '../about/external/initial/GoalRequest.dart';
import '../about/external/initial/IdRequest.dart';
import '../about/external/initial/LoginData.dart';
import '../about/external/initial/ReportCardRequest.dart';
import '../about/external/initial/SessionLogRequest.dart';
import '../about/external/initial/SickModeRequest.dart';
import '../about/external/initial/ToneRequest.dart';
import '../about/internal/application/CapacityProfile.dart';
import '../about/internal/application/MeDescription.dart';
import '../about/internal/application/Token.dart';
import '../about/internal/application/UserDetails.dart';
import '../about/internal/file/ConnectFileStorage.dart';
import '../comms/ConnectComms.dart';
import '../memory/ConnectInternalMemory.dart';
import 'DataManager.dart';

/// The single data gateway. Constructed once in [ParentViewModel] and shared by
/// every screen; it only delegates to its three collaborators.
class AppDataManager implements DataManager {
  ConnectInternalMemory memory;

  ConnectComms comms;

  ConnectFileStorage files;

  AppDataManager(this.memory, this.comms, this.files);

  // ── Memory ────────────────────────────────────────────────────────────────

  @override
  Future<MeDescription> getMyDescription() => memory.getMyDescription();

  @override
  Future setMyDescription(MeDescription description) =>
      memory.setMyDescription(description);

  @override
  Future<String> getNotToken() => memory.getNotToken();

  @override
  Future setNotToken(String token) => memory.setNotToken(token);

  @override
  Future<SystemResponse> getUserCreationDetails() =>
      memory.getUserCreationDetails();

  @override
  Future setUserCreationDetails(SystemResponse response) =>
      memory.setUserCreationDetails(response);

  @override
  Future<UserDetails> getUserDetails() => memory.getUserDetails();

  @override
  Future setUserDetails(UserDetails details) => memory.setUserDetails(details);

  @override
  Future<Token> getTokenEntry() => memory.getTokenEntry();

  @override
  Future setTokenEntry(Token token) => memory.setTokenEntry(token);

  @override
  Future<String> getRefreshAt() => memory.getRefreshAt();

  @override
  Future setRefreshAt(String refresher) => memory.setRefreshAt(refresher);

  @override
  Future<Commitment> getActiveCommitment() => memory.getActiveCommitment();

  @override
  Future setActiveCommitment(Commitment commitment) =>
      memory.setActiveCommitment(commitment);

  @override
  Future<Program> getActiveProgram() => memory.getActiveProgram();

  @override
  Future setActiveProgram(Program program) => memory.setActiveProgram(program);

  @override
  Future<CapacityProfile> getCapacityProfile() => memory.getCapacityProfile();

  @override
  Future setCapacityProfile(CapacityProfile profile) =>
      memory.setCapacityProfile(profile);

  @override
  Future<double> getCachedDebtScore() => memory.getCachedDebtScore();

  @override
  Future setCachedDebtScore(double score) => memory.setCachedDebtScore(score);

  @override
  Future<int> getEngagementCount() => memory.getEngagementCount();

  @override
  Future setEngagementCount(int count) => memory.setEngagementCount(count);

  @override
  Future<int> getAmnestySpent() => memory.getAmnestySpent();

  @override
  Future setAmnestySpent(int spent) => memory.setAmnestySpent(spent);

  @override
  Future<bool> showOnboarding() => memory.showOnboarding();

  @override
  Future setOnboardingOption(bool value) => memory.setOnboardingOption(value);

  // ── Files ─────────────────────────────────────────────────────────────────

  @override
  Future<String> saveProof(String name, Uint8List bytes) =>
      files.saveProof(name, bytes);

  @override
  Future<Uint8List?> readProof(String reference) => files.readProof(reference);

  @override
  Future<bool> deleteProof(String reference) => files.deleteProof(reference);

  @override
  Future<String> proofDirectory() => files.proofDirectory();

  // ── Comms ─────────────────────────────────────────────────────────────────

  @override
  Future<Response> registerDevice(DeviceRequest request) =>
      comms.registerDevice(request);

  @override
  Future<Response> registerDeviceToken(String token) =>
      comms.registerDeviceToken(token);

  @override
  Future<Response> login(LoginData request) => comms.login(request);

  @override
  Future<Response> logout() => comms.logout();

  @override
  Future<Response> me() => comms.me();

  @override
  Future<Response> getMyGoals(HistoryRequest request) =>
      comms.getMyGoals(request);

  @override
  Future<Response> saveGoalEntry(GoalRequest request) =>
      comms.saveGoalEntry(request);

  @override
  Future<Response> getGoalTasks(IdRequest request) =>
      comms.getGoalTasks(request);

  @override
  Future<Response> archiveGoalEntry(IdRequest request) =>
      comms.archiveGoalEntry(request);

  @override
  Future<Response> getTodayPlan(CommitmentsRequest request) =>
      comms.getTodayPlan(request);

  @override
  Future<Response> getMyCommitments(CommitmentsRequest request) =>
      comms.getMyCommitments(request);

  @override
  Future<Response> getOverdueQueue(HistoryRequest request) =>
      comms.getOverdueQueue(request);

  @override
  Future<Response> saveCommitmentEntry(CommitmentRequest request) =>
      comms.saveCommitmentEntry(request);

  @override
  Future<Response> updateCommitmentEntry(CommitmentRequest request) =>
      comms.updateCommitmentEntry(request);

  @override
  Future<Response> deleteCommitmentEntry(IdRequest request) =>
      comms.deleteCommitmentEntry(request);

  @override
  Future<Response> completeCommitmentEntry(CompletionRequest request) =>
      comms.completeCommitmentEntry(request);

  @override
  Future<Response> deferCommitmentEntry(DeferralRequest request) =>
      comms.deferCommitmentEntry(request);

  @override
  Future<Response> abandonCommitmentEntry(AbandonRequest request) =>
      comms.abandonCommitmentEntry(request);

  @override
  Future<Response> getCommitmentHistory(HistoryRequest request) =>
      comms.getCommitmentHistory(request);

  @override
  Future<Response> getCommitmentEvents(IdRequest request) =>
      comms.getCommitmentEvents(request);

  @override
  Future<Response> checkCapacity(CommitmentsRequest request) =>
      comms.checkCapacity(request);

  @override
  Future<Response> getCapacityProfileEntry() => comms.getCapacityProfileEntry();

  @override
  Future<Response> getDebtSummary() => comms.getDebtSummary();

  @override
  Future<Response> getDebtLedger(HistoryRequest request) =>
      comms.getDebtLedger(request);

  @override
  Future<Response> getDebtTrend(ReportCardRequest request) =>
      comms.getDebtTrend(request);

  @override
  Future<Response> getStanding() => comms.getStanding();

  @override
  Future<Response> getStandingHistory(HistoryRequest request) =>
      comms.getStandingHistory(request);

  @override
  Future<Response> getExcuseClusters(ReportCardRequest request) =>
      comms.getExcuseClusters(request);

  @override
  Future<Response> uploadPhotoProof(FormData request) =>
      comms.uploadPhotoProof(request);

  @override
  Future<Response> submitTimerProofEntry(CompletionRequest request) =>
      comms.submitTimerProofEntry(request);

  @override
  Future<Response> submitLocationProofEntry(CompletionRequest request) =>
      comms.submitLocationProofEntry(request);

  @override
  Future<Response> spendAmnestyToken(AmnestyRequest request) =>
      comms.spendAmnestyToken(request);

  @override
  Future<Response> getAmnestyBalance() => comms.getAmnestyBalance();

  @override
  Future<Response> updateSickMode(SickModeRequest request) =>
      comms.updateSickMode(request);

  @override
  Future<Response> checkDistress() => comms.checkDistress();

  @override
  Future<Response> updateTone(ToneRequest request) => comms.updateTone(request);

  @override
  Future<Response> getMyHabits(HistoryRequest request) =>
      comms.getMyHabits(request);

  @override
  Future<Response> saveHabitEntry(Map<String, dynamic> request) =>
      comms.saveHabitEntry(request);

  @override
  Future<Response> logHabitEntry(IdRequest request) =>
      comms.logHabitEntry(request);

  @override
  Future<Response> getKeystoneHabits() => comms.getKeystoneHabits();

  @override
  Future<Response> getMyRoutines(HistoryRequest request) =>
      comms.getMyRoutines(request);

  @override
  Future<Response> logRoutineChainEntry(Map<String, dynamic> request) =>
      comms.logRoutineChainEntry(request);

  @override
  Future<Response> getMyPrograms(HistoryRequest request) =>
      comms.getMyPrograms(request);

  @override
  Future<Response> saveProgramEntry(Map<String, dynamic> request) =>
      comms.saveProgramEntry(request);

  @override
  Future<Response> activateProgramEntry(IdRequest request) =>
      comms.activateProgramEntry(request);

  @override
  Future<Response> getProgramSessions(IdRequest request) =>
      comms.getProgramSessions(request);

  @override
  Future<Response> startSessionEntry(IdRequest request) =>
      comms.startSessionEntry(request);

  @override
  Future<Response> saveSessionLogEntry(SessionLogRequest request) =>
      comms.saveSessionLogEntry(request);

  @override
  Future<Response> getSessionHistory(HistoryRequest request) =>
      comms.getSessionHistory(request);

  @override
  Future<Response> getLastSessionFor(IdRequest request) =>
      comms.getLastSessionFor(request);

  @override
  Future<Response> getWeeklyVolume(ReportCardRequest request) =>
      comms.getWeeklyVolume(request);

  @override
  Future<Response> getContactVolume(ReportCardRequest request) =>
      comms.getContactVolume(request);

  @override
  Future<Response> getPersonalRecords(HistoryRequest request) =>
      comms.getPersonalRecords(request);

  @override
  Future<Response> getWeeklyReportCard(ReportCardRequest request) =>
      comms.getWeeklyReportCard(request);

  @override
  Future<Response> getMonthlyReportCard(ReportCardRequest request) =>
      comms.getMonthlyReportCard(request);

  @override
  Future<Response> getMyNotifications(HistoryRequest request) =>
      comms.getMyNotifications(request);

  @override
  Future<Response> acknowledgeNudgeEntry(IdRequest request) =>
      comms.acknowledgeNudgeEntry(request);
}
