// Author: fengshengxiong
// Date: 2024/5/10
// Description: 本地路径

import 'dart:io';
import 'package:path_provider/path_provider.dart';

class LocalPathUtil {
  /// 获取临时目录
  /// `NSCachesDirectory` on iOS and macOS
  /// `Context.getCacheDir` on Android.
  static Future<Directory> getTemporaryPath() async {
    return await getTemporaryDirectory();
  }

  /// 获取应用支持目录
  /// `NSApplicationSupportDirectory` on iOS and macOS.
  /// The Flutter engine's `PathUtils.getFilesDir` API on Android.
  static Future<Directory> getSupportPath() async {
    return await getApplicationSupportDirectory();
  }

  /// 获取应用文档目录
  /// `NSDocumentDirectory` on iOS and macOS.
  /// The Flutter engine's `PathUtils.getDataDirectory` API on Android.
  static Future<Directory> getDocumentsPath() async {
    return await getApplicationDocumentsDirectory();
  }

  /// 获取录音文件保存目录
  static Future<Directory> getRecordingsDir() async {
    Directory cacheDir = await getTemporaryPath();
    Directory recordingsDir = Directory('${cacheDir.path}/recordings');
    bool exist = await recordingsDir.exists();
    if (!exist) {
      // 若目录不存在，先创建
      await recordingsDir.create();
    }
    return recordingsDir;
  }

  /// 获取录音文件保存目录
  static Future<Directory> getAssetsDir() async {
    Directory cacheDir = await getTemporaryPath();
    Directory recordingsDir = Directory('${cacheDir.path}/assets');
    bool exist = await recordingsDir.exists();
    if (!exist) {
      // 若目录不存在，先创建
      await recordingsDir.create();
    }
    return recordingsDir;
  }

  /// 获取音频文件变声后输出目录
  static Future<Directory> getVoiceChangeOutputDir() async {
    Directory cacheDir = await getDocumentsPath();
    Directory recordingsDir = Directory('${cacheDir.path}/change_voice');
    bool exist = await recordingsDir.exists();
    if (!exist) {
      // 若目录不存在，先创建
      await recordingsDir.create();
    }
    return recordingsDir;
  }

  /// 获取音乐文件下载目录
  static String getMusicDownloadDir() {
    return 'music_download';
  }
}