import 'package:json_annotation/json_annotation.dart';

import '../files_sharing/queries/share/share.dart';

part 'autocomplete_response.g.dart';

/// Maps an autocomplete result's `source` to the matching Nextcloud share type.
/// Groups become [kShareTypeGroup]; everything else (users, and any unknown
/// source) defaults to [kShareTypeUser].
int shareTypeFromSource(String? source) {
  if (source != null && source.startsWith('groups')) return kShareTypeGroup;
  return kShareTypeUser;
}

@JsonSerializable(explicitToJson: true)
class AutocompleteResponse {
  List<AutocompleteResponseObject> data;

  AutocompleteResponse(this.data);

  factory AutocompleteResponse.fromJson(Map<String, dynamic> json) =>
      _$AutocompleteResponseFromJson(json);
  Map<String, dynamic> toJson() => _$AutocompleteResponseToJson(this);
}

@JsonSerializable()
class AutocompleteResponseObject {
  String id;
  String label;
  String? icon;
  String? source;
  String? status;
  String? subline;
  String? shareWithDisplayNameUniqe;

  AutocompleteResponseObject(
    this.id,
    this.label,
    this.icon,
    this.source,
    this.status,
    this.subline,
    this.shareWithDisplayNameUniqe,
  );

  factory AutocompleteResponseObject.fromJson(Map<String, dynamic> json) =>
      _$AutocompleteResponseObjectFromJson(json);
  Map<String, dynamic> toJson() => _$AutocompleteResponseObjectToJson(this);
}
