import 'package:electronic_assistant/data/api/atmob_api.dart';
import 'package:electronic_assistant/data/api/request/talk_delete_request.dart';

import '../../utils/http_handler.dart';
import '../api/request/talk_generate_request.dart';
import '../api/request/talk_rename_request.dart';
import '../api/request/talk_request.dart';
import '../api/response/talk_check_electric_response.dart';
import '../api/response/talk_detail_response.dart';

class TalkRepository {
  TalkRepository._();

  // duration 音频时长，单位为秒
  Future<TalkCheckElectricResponse> checkElectric(double duration) {
    return atmobApi
        .checkElectric(TalkGenerateRequest(duration))
        .then(HttpHandler.handle(false));
  }

  Future<TalkDetailResponse> talkInfo(String id) {
    return atmobApi.talkInfo(TalkRequest(id)).then(HttpHandler.handle(true));
  }

  Future<void> talkRename(String? id, String? title) {
    return atmobApi
        .talkRename(TalkRenameRequest(id, title))
        .then(HttpHandler.handle(true));
  }

  Future<void> talkDelete(String? id) {
    return atmobApi
        .talkDelete(TalkDeleteRequest(id))
        .then(HttpHandler.handle(true));
  }
}

final talkRepository = TalkRepository._();
