/*
 * @Author: XianKaiQun
 * @Date: 2020-05-12 10:35:00
 * @LastEditors: wuwei
 * @LastEditTime: 2023-12-18 17:23:04
 * @Description:
 */
import 'package:app_package/src/models/app_page_setting.dart';
import 'package:app_package/src/models/app_page_setting_detail.dart';
import 'package:app_package/src/models/auth_list.dart';
import 'package:app_package/src/models/company_community.dart';
import 'package:app_package/src/models/device_statistics.dart';
import 'package:app_package/src/models/dynamic_item.dart';
import 'package:app_package/src/models/dynamic_statistics.dart';
import 'package:app_package/src/models/fee_statistics.dart';
import 'package:app_package/src/models/form_menu_id_detail.dart';
import 'package:app_package/src/models/hgj_menu.dart';
import 'package:app_package/src/models/menu_detail.dart';
import 'package:app_package/src/models/menu_list.dart';
import 'package:app_package/src/models/meter_statistics.dart';
import 'package:app_package/src/models/notice_detail.dart';
import 'package:app_package/src/models/notice_list.dart';
import 'package:app_package/src/models/notice_statistics.dart';
import 'package:app_package/src/models/repair_report.dart';
import 'package:app_package/src/models/state_menu.dart';
import 'package:app_package/src/models/task_fee.dart';
import 'package:app_package/src/models/task_list.dart';
import 'package:app_package/src/models/task_statistics.dart';

import '../../app_package.dart';
import '../models/industry_news_list.dart';

class RootApi {
  static String _prefix = '/app/admin';

  ///权限菜单
  ///http://yapi.wisdomcity.com.cn/project/16/interface/api/4231
  static Future<ResModel<List<HgjMenuModel>?>> getMenuList(data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix/hgjMenu/v3',
      queryParameters: data,
    );

    return ResModel<List<HgjMenuModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<HgjMenuModel>((f) => HgjMenuModel.fromJson(f)).toList(),
    );
  }

  ///获取登陆人的快捷菜单
  ///http://yapi.wisdomcity.com.cn/project/16/interface/api/4231
  static Future<ResModel<List<HgjMenuModel>?>> getFastMenuList(data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix/hgjMenu/v1/quick',
      queryParameters: data,
    );

    return ResModel<List<HgjMenuModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<HgjMenuModel>((f) => HgjMenuModel.fromJson(f)).toList(),
    );
  }

  ///设置登陆人的快捷菜单
  static Future<ResModel<int?>> postFastMenuList(data) async {
    var res = await HttpUtil.instance.post(
      '$_prefix/hgjMenu/v1/quick',
      data: data,
    );

    return ResModel<int?>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }

  ///设置登陆人的快捷菜单
  static Future<ResModel<int?>> deleteFastMenuList(data) async {
    var res = await HttpUtil.instance.delete(
      '$_prefix/hgjMenu/v1/quick',
      data: data,
    );

    return ResModel<int?>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }

  /// 可查看表单列表
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/19319
  static Future<ResModel<List<StateMenu>?>> getStateMenuList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/intelligentForm/getAuthorizeViewForms',
    );
    return ResModel<List<StateMenu>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<StateMenu>((f) => StateMenu.fromJson(f)).toList(),
    );
  }

  /// 表单详情
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/19328
  static Future<ResModel<MenuDetail>> getMenuFormDetail(id) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/intelligentFormFill/$id',
    );

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

  /// 表单列表
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/19337
  static Future<ResModel<List<MenuList>?>> getMenuFormList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/intelligentFormFill/getAppFillByFormIdentification/${data['formIdentification']}',
      queryParameters: data,
    );
    return ResModel<List<MenuList>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<MenuList>((f) => MenuList.fromJson(f)).toList(),
    );
  }

  static Future<ResModel<PagingModel<MenuList>>> getMenuFormListPaging(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/intelligentFormFill/getAppFillByFormIdentificationV3/${data['formIdentification']}',
      queryParameters: data,
    );

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

  /// 表单详情按标识查询
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/19837
  static Future<ResModel<FormMenuIdDetailModel>> getFormIdDetail(
      formIdentification) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/intelligentForm/byFormIdentification/$formIdentification',
    );

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

  /// app页面设置列表
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/19762
  static Future<ResModel<AppPageSettingModel>> getAppPageSettingList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/appPageSet',
    );

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

  ///  app页面设置详情
  ///   http://yapi.wisdomcity.com.cn/project/40/interface/api/19767
  static Future<ResModel<AppPageSettingDetailModel>> getAppPageSettingDetail(
      id, data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/appPageSet/$id',
      queryParameters: data,
    );

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

  /// 功能模块入口小红点提示
  static Future<ResModel<List<MenusNoticeModel>>> getMenusNotice(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/appPageBadge',
      queryParameters: data,
    );

    return ResModel<List<MenusNoticeModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<MenusNoticeModel>((f) => MenusNoticeModel.fromJson(f))
          .toList(),
    );
  }

  /// 首页公告
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20087
  static Future<ResModel<List<NoticeListModel>>> getIndexNoticeList(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/noticePublication/login',
      queryParameters: data,
    );

    return ResModel<List<NoticeListModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<NoticeListModel>((f) => NoticeListModel.fromJson(f))
          .toList(),
    );
  }

  /// 员工公告列表
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20092
  static Future<ResModel<PagingModel<NoticeListModel>>> getNoticeList(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/noticePublication',
      queryParameters: data,
    );

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

  /// 员工公告详情
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20097
  static Future<ResModel<NoticeDetailModel>> getNoticeDetail(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/noticePublication/${data['id']}',
    );

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

  /// 版本信息
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20437

  static Future<String> getTypeAndVersion(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/appUpdateManagement/getByPlatformTypeAndVersion',
      queryParameters: data,
    );

    if (res.data['data'] != null && res.data['data'] is String) {
      return res.data['data'];
    } else {
      return '';
    }
  }

  /// 登录人授权填报表单列表
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20754
  static Future<ResModel<List<AuthListModel>>> getAuthList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/intelligentFormFill/getAuthorizeFillForms/',
    );

    return ResModel<List<AuthListModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<AuthListModel>((f) => AuthListModel.fromJson(f))
          .toList(),
    );
  }

  /// 智能表单填报
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20746
  static Future<ResModel<String>> postIntelligentForm(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/intelligentFormFill',
      data: data,
    );
    return ResModel<String>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }

  /// 智能表单修改
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20748
  static Future<ResModel<int>> putIntelligentForm(id, data) async {
    var res = await HttpUtil.instance.put(
      '/app/admin/intelligentFormFill/$id',
      data: data,
    );
    return ResModel<int>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }

  /// 授权小区
  ///
  static Future<ResModel<List<CompanyCommunityModel>>>
      getAuthCompanyCommunity() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/allTree',
    );

    return ResModel<List<CompanyCommunityModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<CompanyCommunityModel>((f) => CompanyCommunityModel.fromJson(f))
          .toList(),
    );
  }

  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/cat_236
  ////服务动态列表
  Future<ResModel<PagingModel<DynamicItemModel>>> getDynamicList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/communityMessage',
      queryParameters: data,
    );

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

  ////草稿箱列表
  Future<ResModel<PagingModel<DynamicItemModel>>> getDynamicDraftList(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/communityMessage/draft/list',
      queryParameters: data,
    );

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

  /// 收费卡片
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20988
  static Future<ResModel<FeeStatisticsModel>> getFeeStatistics(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/hgj/pay/statistics/collectionRate',
      queryParameters: data,
    );

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

  ///抄表统计
  ///http://yapi.wisdomcity.com.cn/project/40/interface/api/21003
  static Future<ResModel<MeterStatisticsModel>> getMeterStatistics(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/meterReading/homePage/statistic',
      queryParameters: data,
    );

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

  /// 智能设备统计
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/21008
  static Future<ResModel<List<DeviceStatisticsModel>>> getSmartDeviceStatistics(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/smartDevice/homePage/statistic',
      queryParameters: data,
    );

    return ResModel<List<DeviceStatisticsModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<DeviceStatisticsModel>((f) => DeviceStatisticsModel.fromJson(f))
          .toList(),
    );
  }

  /// 任务工单统计
  ///
  static Future<ResModel<TaskStatisticsModel>> getTaskStatistics() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/excutive/homePage/statistic',
    );

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

  /// 任务卡片列表
  static Future<ResModel<List<TaskListModel>>> getTaskList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/excutive/homePage/list',
    );

    return ResModel<List<TaskListModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<TaskListModel>((f) => TaskListModel.fromJson(f))
          .toList(),
    );
  }

  /// 罚金
  static Future<ResModel<TaskFeeModel>> getTaskFee(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/penaltyBill/feeSum',
      queryParameters: data,
    );

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

  /// 通知公告统计
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/21018
  static Future<ResModel<NoticeStatisticsModel>> getNoticeStatistics(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/notice/homePage/statistic',
      queryParameters: data,
    );

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

  /// 服务动态统计
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/21023
  static Future<ResModel<DynamicStatisticsModel>> getDynamicStatistics(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/dynamicServe/homePage/statistic',
      queryParameters: data,
    );

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

  /// 报事报修统计
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/21013
  static Future<ResModel<RepairReportModel>> getRepairReport(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/reportAndRepair/homePage/statistic',
      queryParameters: data,
    );

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

  static Future<ResModel<PagingModel<IndustryNewsListModel>>> getIndexNews(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/news/page',
      queryParameters: data,
    );

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