import 'package:get/get.dart';
import 'package:json_annotation/json_annotation.dart';

part 'talks.g.dart';

@JsonSerializable()
class TalkBean {
  @JsonKey(name: 'id')
  late final String id;

  @JsonKey(name: 'taskId')
  String? taskId;

  @JsonKey(name: 'ssid')
  String? ssid;

  @JsonKey(name: 'audioUrl')
  String? audioUrl;

  @JsonKey(name: 'duration')
  double? duration;

  @JsonKey(name: 'characters')
  int? characters;

  @JsonKey(name: 'localAudioUrl')
  String? localAudioUrl;

  @JsonKey(name: 'status', fromJson: _intFromJson, includeToJson: false)
  Rxn<int> status;

  @JsonKey(name: 'title', fromJson: _stringFromJson, includeToJson: false)
  Rxn<String> title;

  @JsonKey(name: 'summary', fromJson: _stringFromJson, includeToJson: false)
  Rxn<String> summary;

  @JsonKey(name: 'createTime')
  String? createTime;

  @JsonKey(name: 'templateId')
  int? templateId;

  @JsonKey(name: 'example')
  bool? isExample;

  @JsonKey(name: 'oversizeFile')
  bool? oversizeFile;

  @JsonKey(name: 'uploadType')
  int? uploadType;

  @JsonKey(name: 'progress', fromJson: _intFromJson, includeToJson: false)
  Rxn<int> progress = Rxn(0);

  @JsonKey(
      name: 'progressContent', fromJson: _stringFromJson, includeToJson: false)
  Rxn<String> progressContent = Rxn('');

  TalkBean({
    required this.id,
    this.taskId,
    this.ssid,
    this.audioUrl,
    this.duration,
    this.templateId,
    this.characters,
    required this.status,
    required this.title,
    required this.summary,
    this.createTime,
    this.isExample,
    this.oversizeFile,
    this.uploadType,
    this.localAudioUrl,
    required this.progress,
    required this.progressContent,
  });

  factory TalkBean.fromJson(Map<String, dynamic> json) =>
      _$TalkBeanFromJson(json);

  static _stringFromJson(String? txt) => Rxn(txt);

  static _intFromJson(int? txt) => Rxn(txt);

  void updateBean(TalkBean talkBean) {
    taskId = talkBean.taskId;
    ssid = talkBean.ssid;
    audioUrl = talkBean.audioUrl;
    duration = talkBean.duration;
    characters = talkBean.characters;
    status.value = talkBean.status.value;
    title.value = talkBean.title.value;
    summary.value = talkBean.summary.value;
    templateId = talkBean.templateId;
    createTime = talkBean.createTime;
    isExample = talkBean.isExample;
    oversizeFile = talkBean.oversizeFile;
    uploadType = talkBean.uploadType;
    localAudioUrl = talkBean.localAudioUrl;
    progress.value = talkBean.progress.value;
    progressContent.value = talkBean.progressContent.value;
  }

  @override
  String toString() {
    return 'TalkBean{id: $id, taskId: $taskId, ssid: $ssid, audioUrl: $audioUrl, duration: $duration, characters: $characters, localAudioUrl: $localAudioUrl, status: $status, title: $title, summary: $summary, createTime: $createTime, templateId: $templateId, isExample: $isExample, oversizeFile: $oversizeFile, uploadType: $uploadType, progress: $progress, progressContent: $progressContent}';
  }
}

class TalkStatus {
  TalkStatus._();

  //(0等待生成 1生成中,都处于生成中)  2成功 3失败 4未分析
  static int analysing = 0;
  static int waitAnalysis = 1;
  static int analysisSuccess = 2;
  static int analysisFail = 3;
  static int notAnalysis = 4;
}

class TalkUploadType {
  TalkUploadType._();

  static int record = 0;
  static int localUpload = 1;
}
