import 'package:nut_player_example/src/common/repository/settings_repository.dart';
import 'package:nut_player_example/src/features/settings_screen/domain/settings_bloc.dart';

class SettingsMapper {
  static RepositoryFullscreenSettings repoFullscreenSettings(FullscreenSettings setting) {
    switch (setting) {
      case FullscreenSettings.landscape:
        return RepositoryFullscreenSettings.landscape;
      case FullscreenSettings.flexible:
        return RepositoryFullscreenSettings.flexible;
      case FullscreenSettings.off:
        return RepositoryFullscreenSettings.off;
    }
  }

  static RepositoryVideoQualityNaming repoQualityNaming(String naming) {
    switch (naming) {
      case "common":
        return RepositoryVideoQualityNaming.common;
      case "rus":
        return RepositoryVideoQualityNaming.rus;
      case "eng":
        return RepositoryVideoQualityNaming.eng;
      case "resolution":
        return RepositoryVideoQualityNaming.resolution;
      default:
        return RepositoryVideoQualityNaming.common;
    }
  }

  static VideoQualityNaming qualityNaming(RepositoryVideoQualityNaming naming) {
    switch (naming) {
      case RepositoryVideoQualityNaming.common:
        return VideoQualityNaming.common;
      case RepositoryVideoQualityNaming.rus:
        return VideoQualityNaming.rus;
      case RepositoryVideoQualityNaming.eng:
        return VideoQualityNaming.eng;
      case RepositoryVideoQualityNaming.resolution:
        return VideoQualityNaming.resolution;
      default:
        return VideoQualityNaming.common;
    }
  }

  static RepositoryVideoQuality repoVideoQuality(String setting) {
    switch (setting) {
      case "auto":
        return RepositoryVideoQuality.auto;
      case "p144":
        return RepositoryVideoQuality.p144;
      case "p240":
        return RepositoryVideoQuality.p240;
      case "p360":
        return RepositoryVideoQuality.p360;
      case "p480":
        return RepositoryVideoQuality.p480;
      case "p720":
        return RepositoryVideoQuality.p720;
      case "p1080":
        return RepositoryVideoQuality.p1080;
      case "p1440":
        return RepositoryVideoQuality.p1440;
      case "p2160":
        return RepositoryVideoQuality.p2160;
      default:
        return RepositoryVideoQuality.auto;
    }
  }

  static VideoQuality quality(RepositoryVideoQuality videoQuality) {
    switch (videoQuality) {
      case RepositoryVideoQuality.auto:
        return VideoQuality.auto;
      case RepositoryVideoQuality.p2160:
        return VideoQuality.p2160;
      case RepositoryVideoQuality.p1440:
        return VideoQuality.p1440;
      case RepositoryVideoQuality.p1080:
        return VideoQuality.p1080;
      case RepositoryVideoQuality.p720:
        return VideoQuality.p720;
      case RepositoryVideoQuality.p480:
        return VideoQuality.p480;
      case RepositoryVideoQuality.p360:
        return VideoQuality.p360;
      case RepositoryVideoQuality.p240:
        return VideoQuality.p240;
      case RepositoryVideoQuality.p144:
        return VideoQuality.p144;
    }
  }

  static FullscreenSettings fullscreenSetting(RepositoryFullscreenSettings settings) {
    switch (settings) {
      case RepositoryFullscreenSettings.landscape:
        return FullscreenSettings.landscape;
      case RepositoryFullscreenSettings.flexible:
        return FullscreenSettings.flexible;
      case RepositoryFullscreenSettings.off:
        return FullscreenSettings.off;
    }
  }

  static SkinColor skinColor(RepositorySkinColor skinColor) {
    switch (skinColor) {
      case RepositorySkinColor.white:
        return SkinColor.white;
    }
  }

  static LogType logType(RepositoryLogType logType) {
    switch (logType) {
      case RepositoryLogType.off:
        return LogType.off;
      case RepositoryLogType.info:
        return LogType.info;
      case RepositoryLogType.debug:
        return LogType.debug;
    }
  }

  static Map<String, dynamic> qualityDictionary(RepositoryVideoQuality quality) {
    switch (quality) {
      case RepositoryVideoQuality.auto:
        return _createQualityMap(bandwidth: 0, width: 0, height: 0);
      case RepositoryVideoQuality.p2160:
        return _createQualityMap(bandwidth: 32000000, width: 3840, height: 2160);
      case RepositoryVideoQuality.p1440:
        return _createQualityMap(bandwidth: 12000000, width: 2560, height: 1440);
      case RepositoryVideoQuality.p1080:
        return _createQualityMap(bandwidth: 8000000, width: 1920, height: 1080);
      case RepositoryVideoQuality.p720:
        return _createQualityMap(bandwidth: 3500000, width: 1280, height: 720);
      case RepositoryVideoQuality.p480:
        return _createQualityMap(bandwidth: 1800000, width: 854, height: 480);
      case RepositoryVideoQuality.p360:
        return _createQualityMap(bandwidth: 1200000, width: 640, height: 360);
      case RepositoryVideoQuality.p240:
        return _createQualityMap(bandwidth: 800000, width: 426, height: 240);
      case RepositoryVideoQuality.p144:
        return _createQualityMap(bandwidth: 400000, width: 256, height: 144);
      default:
        return _createQualityMap(bandwidth: 0, width: 0, height: 0);
    }
  }

  static Map<String, int> _createQualityMap({required int bandwidth,
    required int width,
    required int height}) {
    return {
      'bandwidth': bandwidth,
      'height': height,
      'width': width,
    };
  }
}