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

class QualityControlManager extends BaseManager
    implements IQualityControlManager {
  @override
  Future<bool> addConsultationReportQuality({
    required String consultationRecordCode,
    required String reportCode,
    required int qualityTypeKey,
  }) async {
    return await rpc.liveConsultation.addConsultationReportQualityAsync(
      AddConsultationReportQualityRequest(
        token: token,
        qualityTypeKey: qualityTypeKey,
        reportCode: reportCode,
        consultationRecordCode: consultationRecordCode,
      ),
    );
  }

  @override
  Future<bool> modifyConsultationReportQualityAsync({
    required String consultationRecordCode,
    required String reportCode,
    required int qualityTypeKey,
  }) async {
    return await rpc.liveConsultation.modifyConsultationReportQualityAsync(
      ModifyConsultationReportQualityRequest(
        token: token,
        qualityTypeKey: qualityTypeKey,
        reportCode: reportCode,
        consultationRecordCode: consultationRecordCode,
      ),
    );
  }

  @override
  String getQualityTitle(QualityType qualityType) {
    String qualityTitle = i18nBook.common.qualityControl.t;
    switch (qualityType) {
      case QualityType.None:
        break;
      case QualityType.Qualified:
        qualityTitle = i18nBook.common.qualityPass.t;
        break;
      case QualityType.InformationUnCompleted:
        qualityTitle = i18nBook.common.infoIncomplete.t;
        break;
      case QualityType.ImageNotClear:
        qualityTitle = i18nBook.common.imageNotStandard.t;
        break;
      case QualityType.PositiveSiteNotClear:
        qualityTitle = i18nBook.common.lesionNotClear.t;
        break;
    }
    return qualityTitle;
  }

  @override
  String getQualityState(QualifiedState qualityType) {
    switch (qualityType) {
      case QualifiedState.UnSet:
        return "";
      case QualifiedState.Qualified:
        return i18nBook.common.qualityControlled.t;
      case QualifiedState.UnQualified:
        return "";
    }
  }

  @override
  Future<bool> addRecordReportQuality(
      {required String recordCode,
      required String reportCode,
      required String option,
      required List<QualityControlScoreItem> scoreItems}) async {
    return await rpc.recordInfo.addRecordReportQualityAsync(
      AddRecordReportQualityRequest(
        token: token,
        recordCode: recordCode,
        reportCode: reportCode,
        qualityControlScoreList: scoreItems,
        opinion: option,
      ),
    );
  }

  @override
  Future<bool> addRemedicalQuality(
      {required String recordCode,
      required String remedicalCode,
      required String option,
      required List<QualityControlScoreItem> scoreItems}) async {
    return await rpc.recordInfo.addRemedicalQualityAsync(
      AddRemedicalQualityRequest(
        token: token,
        recordCode: recordCode,
        remedicalCode: remedicalCode,
        qualityControlScoreList: scoreItems,
        opinion: option,
      ),
    );
  }

  @override
  Future<bool> modifyRecordReportQuality(
      {required String recordCode,
      required String reportCode,
      required String option,
      required List<QualityControlScoreItem> scoreItems}) async {
    return await rpc.recordInfo.modifyRecordReportQualityAsync(
      ModifyRecordReportQualityRequest(
        token: token,
        recordCode: recordCode,
        reportCode: reportCode,
        qualityControlScoreList: scoreItems,
        opinion: option,
      ),
    );
  }

  @override
  Future<bool> modifyRemedicalQuality(
      {required String recordCode,
      required String remedicalCode,
      required String option,
      required List<QualityControlScoreItem> scoreItems}) async {
    return await rpc.recordInfo.modifyRemedicalQualityAsync(
      ModifyRemedicalQualityRequest(
        token: token,
        recordCode: recordCode,
        remedicalCode: remedicalCode,
        qualityControlScoreList: scoreItems,
        opinion: option,
      ),
    );
  }
}
