import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:hmg_nurses/model/base/post_params_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;

  final PostParamsModel _postParamsInitConfig = PostParamsModel(
    tokenID: "@dm!n",
    languageID: 2,
    stamp: "",
    iPAdress: "9.9.9.9",
    versionID: 8.3,
    channel: 9,
    sessionID: "BlUSkYymTt",
    isLoginForDoctorApp: true,
    patientOutSA: false,
    vidaAuthTokenID: null,
    vidaRefreshTokenID: null,
    deviceTypeID: 1,
  );

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

  PostParamsModel? _postParams;

  PostParamsModel? get postParamsObject => _postParams;

  // Map<String, dynamic> get postParamsJson => isLogged ? (_postParams?.toJsonAfterLogin() ?? {}) : (_postParams?.toJson() ?? {});
  Map<String, dynamic> get postParamsJson{
    _postParams!.stamp=DateTime.now().toIso8601String();
    return _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;

  set setUserName(v) => _username = v;

  String? get getUserName => _username;
}
