import 'package:app_package/app_package.dart';
import '../community_service.dart';
import '../../models/community_list_models.dart';
import '../../models/community_detail_models.dart';

class CommunityServiceImpl implements CommunityService {
  static String prefix = '/app/admin/communityListing';

  /// 小区管理列表
  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/9329
  @override
  Future<ResModel<List<CommunityListModel>?>> getCommunityList(data) async {
    var res = await HttpUtil.instance.get(
      '$prefix/list',
      queryParameters: data,
    );
    return ResModel<List<CommunityListModel>?>(
      json: res.data,
      to: (v) => {(v ?? []).map((f) => f.toJson()).toList()},
      from: (v) => (v ?? [])
          .map<CommunityListModel>((f) => CommunityListModel.fromJson(f))
          .toList(),
    );
  }

  Future<ResModel<CommunityDetailModel>> getCommunityDetail(data) async {
    var res = await HttpUtil.instance.get(
      '$prefix/detail',
      queryParameters: data,
    );

    return ResModel<CommunityDetailModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => CommunityDetailModel.fromJson(v),
    );
  }
}
