//Question for Jordan - is this for an individual token or could it be a span? import 'dart:convert'; import 'package:http/http.dart'; import '../config/environment.dart'; import '../constants/model_keys.dart'; import '../network/requests.dart'; import '../network/urls.dart'; class FullTextTranslationRepo { static Future translate({ required String accessToken, required FullTextTranslationRequestModel request, }) async { final Requests req = Requests( choreoApiKey: Environment.choreoApiKey, accessToken: accessToken, ); final Response res = await req.post( url: PApiUrls.simpleTranslation, body: request.toJson(), ); return FullTextTranslationResponseModel.fromJson( jsonDecode(utf8.decode(res.bodyBytes)), ); } } class FullTextTranslationRequestModel { String text; String? srcLang; String tgtLang; String userL1; String userL2; bool? deepL; int? offset; int? length; FullTextTranslationRequestModel({ required this.text, this.srcLang, required this.tgtLang, required this.userL2, required this.userL1, this.deepL = false, this.offset, this.length, }); //PTODO throw error for null Map toJson() => { "text": text, ModelKey.srcLang: srcLang, ModelKey.tgtLang: tgtLang, ModelKey.userL2: userL2, ModelKey.userL1: userL1, ModelKey.deepL: deepL, ModelKey.offset: offset, ModelKey.length: length, }; } class FullTextTranslationResponseModel { List translations; /// detected source /// PTODO - String source; String? deepL; FullTextTranslationResponseModel({ required this.translations, required this.source, required this.deepL, }); factory FullTextTranslationResponseModel.fromJson(Map json) { return FullTextTranslationResponseModel( translations: (json["translations"] as Iterable) .map( (e) => e, ) .toList() .cast(), source: json[ModelKey.srcLang], deepL: json['deepl_res'], ); } String get bestTranslation => deepL ?? translations.first; }