import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../../resource/assets.gen.dart';
import '../../resource/string.gen.dart';

enum RecordStatus {
  pending,
  recording,
  paused,
}

RecordStatus recordStatusFromName(String name) {
  switch (name) {
    case "pending":
      return RecordStatus.pending;
    case "recording":
      return RecordStatus.recording;
    case "paused":
      return RecordStatus.paused;
    default:
      return RecordStatus.pending;
  }
}

enum SampleRate {
  rate8k,
  rate12_8k,
  rate16k,
  rate22_05k,
  rate24k,
  rate32k,
  rate44_1k,
}

enum Channel {
  mono,
  stereo,
}

extension SampleRateExtension on SampleRate {
  int get value {
    switch (this) {
      case SampleRate.rate8k:
        return 8000;
      case SampleRate.rate12_8k:
        return 12800;
      case SampleRate.rate16k:
        return 16000;
      case SampleRate.rate22_05k:
        return 22050;
      case SampleRate.rate24k:
        return 24000;
      case SampleRate.rate32k:
        return 32000;
      case SampleRate.rate44_1k:
        return 44100;
    }
  }

  String get desc {
    switch (this) {
      case SampleRate.rate8k:
        return "8k";
      case SampleRate.rate12_8k:
        return "12.8k";
      case SampleRate.rate16k:
        return "16k";
      case SampleRate.rate22_05k:
        return "22.05k";
      case SampleRate.rate24k:
        return "24k";
      case SampleRate.rate32k:
        return "32k";
      case SampleRate.rate44_1k:
        return "44.1k";
    }
  }
}

extension ChannelExtension on Channel {
  int get value {
    switch (this) {
      case Channel.mono:
        return 1;
      case Channel.stereo:
        return 2;
    }
  }

  String get desc {
    switch (this) {
      case Channel.mono:
        return "Mono";
      case Channel.stereo:
        return "Stereo";
    }
  }
}

extension RecordStatusExtension on RecordStatus {
  String get desc {
    switch (this) {
      case RecordStatus.pending:
        return StringName.recordStatusPending.tr;
      case RecordStatus.recording:
        return StringName.recordStatusRecording.tr;
      case RecordStatus.paused:
        return StringName.recordStatusPaused.tr;
    }
  }

  ImageProvider get actionButtonImage {
    switch (this) {
      case RecordStatus.pending:
        return Assets.images.iconRecordStart.provider();
      case RecordStatus.recording:
        return Assets.images.iconRecordPause.provider();
      case RecordStatus.paused:
        return Assets.images.iconRecordResume.provider();
    }
  }

  ImageProvider get saveButtonImage {
    return this == RecordStatus.pending
        ? Assets.images.iconRecordSaveDisable.provider()
        : Assets.images.iconRecordSaveEnable.provider();
  }

  ImageProvider get cancelButtonImage {
    return this == RecordStatus.pending
        ? Assets.images.iconRecordCancelDisable.provider()
        : Assets.images.iconRecordCancelEnable.provider();
  }

  RecordStatus get nextStatus {
    switch (this) {
      case RecordStatus.pending:
        return RecordStatus.recording;
      case RecordStatus.recording:
        return RecordStatus.paused;
      case RecordStatus.paused:
        return RecordStatus.recording;
    }
  }
}
