import '../models/viewer_session.dart';
import '../models/editor_session.dart';
import '../models/annotation_payload.dart';
import '../models/file_meta.dart';
import 'api_client.dart';

class DocumentApi {
  final ApiClient _apiClient;

  DocumentApi(this._apiClient);

  Future<ViewerSession> requestViewerSession(
    String orgId,
    String fileId,
  ) async {
    return await _apiClient.get(
      '/orgs/$orgId/files/$fileId/view',
      fromJson: (data) => ViewerSession.fromJson(data),
    );
  }

  Future<EditorSession> requestEditorSession(
    String orgId,
    String fileId,
  ) async {
    return await _apiClient.get(
      '/orgs/$orgId/files/$fileId/edit',
      fromJson: (data) => EditorSession.fromJson(data),
    );
  }

  Future<void> saveAnnotations(
    String orgId,
    String fileId,
    AnnotationPayload payload,
  ) async {
    await _apiClient.post(
      '/orgs/$orgId/files/$fileId/annotations',
      data: payload.toJson(),
      fromJson: (data) => null,
    );
  }

  Future<FileMeta> getFileMeta(String orgId, String fileId) async {
    return await _apiClient.get(
      '/orgs/$orgId/files/$fileId/meta',
      fromJson: (data) => FileMeta.fromJson(data),
    );
  }
}
