import 'package:electronic_assistant/base/app_base_request.dart';

import '../../utils/http_handler.dart';
import '../api/atmob_api.dart';
import '../api/request/template_delete_request.dart';
import '../api/request/template_update_request.dart';
import '../api/response/template_list_response.dart';

class TemplateRepository {
  TemplateRepository._();

  Future<TemplateListResponse> getTemplateList() {
    return atmobApi
        .templateList(AppBaseRequest())
        .then(HttpHandler.handle(false));
  }

  Future<String?> defaultInfo() {
    return atmobApi
        .defaultInfo(AppBaseRequest())
        .then(HttpHandler.handle(true))
        .then((value) => value.defaultTitle);
  }

  Future<void> templateUpdate(int? id, String name, List<String>? titles) {
    return atmobApi
        .templateUpdate(TemplateUpdateRequest(id, name, titles))
        .then(HttpHandler.handle(true));
  }

  Future<void> templateDelete(int id) {
    return atmobApi
        .templateDelete(TemplateDeleteRequest(id))
        .then(HttpHandler.handle(true));
  }
}

final templateRepository = TemplateRepository._();
