import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart';
import 'package:mohem_flutter_app/models/itg_forms_models/request_detail_model.dart';
import 'package:mohem_flutter_app/models/member_information_list_model.dart';
import 'package:mohem_flutter_app/models/member_login_list_model.dart';
import 'package:mohem_flutter_app/models/post_params_model.dart';
import 'package:mohem_flutter_app/models/privilege_list_model.dart';
import 'package:mohem_flutter_app/models/worklist_response_model.dart';

class AppState {
  static final AppState _instance = AppState._internal();

  AppState._internal();

  factory AppState() => _instance;

  bool isAuthenticated = false;

  set setIsAuthenticated(v) => isAuthenticated = v;

  bool isLogged = false;

  set setLogged(v) => isLogged = v;

  bool? get getIsLogged => isLogged;

  bool businessCardPrivilege = false;

  set setBusinessCardPrivilege(bool v) => businessCardPrivilege = v;

  bool? get getBusinessCardPrivilege => businessCardPrivilege;

  String? forgetPasswordTokenID;

  set setForgetPasswordTokenID(token) => forgetPasswordTokenID = token;

  String? get getForgetPasswordTokenID => forgetPasswordTokenID;

  //Wifi info
  String? _mohemmWifiSSID;

  set setMohemmWifiSSID(v) => _mohemmWifiSSID = v;

  String? get getMohemmWifiSSID => _mohemmWifiSSID;

  String? _mohemmWifiPassword;

  set setMohemmWifiPassword(v) => _mohemmWifiPassword = v;

  String? get getMohemmWifiPassword => _mohemmWifiPassword;

  final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 5.0, mobileType: Platform.isAndroid ? "android" : "ios");

  void setPostParamsInitConfig() {
    isAuthenticated = false;
    isLogged = false;
    _memberLoginList = null;
    _memberInformationList = null;
    _postParams = _postParamsInitConfig;
  }

  PostParamsModel? _postParams;

  PostParamsModel? get postParamsObject => _postParams;

  Map<String, dynamic> get postParamsJson => isLogged ? (_postParams?.toJsonAfterLogin() ?? {}) : (_postParams?.toJson() ?? {});

  void setPostParamsModel(PostParamsModel _postParams) {
    this._postParams = _postParams;
  }

  bool isArabic(context) => EasyLocalization.of(context)?.locale.languageCode == "ar";

  int getLanguageID(context) => EasyLocalization.of(context)?.locale.languageCode == "ar" ? 1 : 2;

  String? _username;

  // todo ''sikander' added password for now, later will remove & improve
  String? password;

  set setUserName(v) => _username = v;

  String? get getUserName => _username;

  set setUserPassword(_password) => password = _password;

  MemberLoginListModel? _memberLoginList;

  MemberLoginListModel? get memberLoginList => _memberLoginList;

  set setMemberLoginListModel(MemberLoginListModel? _memberLoginList) => this._memberLoginList = _memberLoginList;

  MemberInformationListModel? _memberInformationList;

  MemberInformationListModel? get memberInformationList => _memberInformationList;

  set setMemberInformationListModel(MemberInformationListModel? _memberInformationList) => this._memberInformationList = _memberInformationList;

  List<PrivilegeListModel>? _privilegeListModel;

  List<PrivilegeListModel>? get privilegeListModel => _privilegeListModel;

  set setPrivilegeListModel(List<PrivilegeListModel>? _privilegeListModel) => this._privilegeListModel = _privilegeListModel;

  List<WorkListResponseModel>? workList;

  set setWorkList(List<WorkListResponseModel>? _workList) => workList = _workList;

  int? workListIndex;

  set setWorkListIndex(int? _workListIndex) => workListIndex = _workListIndex;

  List<RequestDetails>? requestAllList;

  set setRequestAllList(List<RequestDetails>? _requestAllList) => requestAllList = _requestAllList;

  int? itgWorkListIndex;

  set setItgWorkListIndex(int? _itgWorkListIndex) => itgWorkListIndex = _itgWorkListIndex;

  UserAutoLoginModel? chatDetails;

  set setchatUserDetails(UserAutoLoginModel details) => chatDetails = details;

  UserAutoLoginModel? get getchatUserDetails => chatDetails;
}
