import 'package:vitalapp/architecture/storage/text_storage.dart';
import 'package:vitalapp/managers/interfaces/cachedRecord.dart';

class CachedRecordManager implements ICachedRecordManager {
  @override
  Future<bool?> saveCachedRecord(
    String key,
    String patientCode,
    String type,
    String cached,
  ) async {
    TextStorage cachedRecord = TextStorage(
      fileName: key,
      directory: "patient/$patientCode/$type",
    );
    return cachedRecord.save(cached);
  }

  @override
  Future<String?> readCachedRecord(
    String key,
    String patientCode,
    String type,
  ) async {
    TextStorage cachedRecord = TextStorage(
      fileName: key,
      directory: "patient/$patientCode/$type",
    );
    String? value = await cachedRecord.read();
    return value;
  }

  @override
  Future<bool?> deleteCachedRecord(
    String key,
    String patientCode,
    String type,
  ) async {
    TextStorage cachedRecord = TextStorage(
      fileName: key,
      directory: "patient/$patientCode/$type",
    );
    return cachedRecord.delete();
  }

  @override
  Future<bool?> deleteDirectory(
    String patientCode,
    String type,
  ) async {
    TextStorage cachedRecord = TextStorage(
      fileName: '',
      directory: "patient/$patientCode/$type",
    );
    return cachedRecord.deleteDirectory();
  }
}
