import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/managers/interfaces/report_template.dart';
import 'package:flyinsono/rpc.dart';
import 'package:fis_i18n/i18n.dart';
import 'base_manager.dart';
import 'package:fis_jsonrpc/rpc.dart';

class ReportTemplateManager extends BaseManager
    implements IReportTemplateManager {
  @override
  Future<ReportTemplateDTO> getDefaultTemplate() async {
    final result = await rpc.report.getDefaultReportTemplateContentAsync(
        GetDefaultReportTemplateContentRequest(
      token: Store.user.token,
      languageCode: i18nBook.locale.toCodeString('-'),
    ));
    return result;
  }

  @override
  Future<PageResult<ReportTemplateDTO>> getReportTemplatePage({
    int pageIndex = 1,
    int pageSize = 100,
    String? keyword,
  }) async {
    var result = await rpc.report.getReportTemplatePageAsync(
      FindReportTemplatePagesRequest(
        token: token,
        languageCode: i18nBook.locale.toCodeString('-'),
        reportTemplateName: keyword,
        pageIndex: pageIndex,
        pageSize: pageSize,
      ),
    );
    return result;
  }

  @override
  Future<PageResult<ReportTemplateDTO>> getOrgReportTemplatePage({
    int pageIndex = 1,
    int pageSize = 100,
    String? keyword,
  }) async {
    var result = await rpc.report.getOrgReportTemplatePageAsync(
      FindReportTemplatePagesRequest(
        token: token,
        languageCode: i18nBook.locale.toCodeString('-'),
        reportTemplateName: keyword,
        pageIndex: pageIndex,
        pageSize: pageSize,
      ),
    );
    return result;
  }

  @override
  Future<ReportTemplateDTO> findReportTemplateByCode({String code = ''}) {
    return rpc.report
        .findReportTemplateByCodeAsync(FindReportTemplateByCodeRequest(
      token: token,
      languageCode: i18nBook.locale.toCodeString('-'),
      reportTemplateCode: code,
    ));
  }
}
