import 'package:intl/intl.dart';

class FortePosSession {
  const FortePosSession({
    this.login,
    this.token,
    this.serverTime,
    this.tokenTimeout,
    this.result,
  });

  final String? login;
  final String? token;
  final DateTime? serverTime;
  final int? tokenTimeout;
  final ResultBean? result;

  static FortePosSession fromJson(Map<String, dynamic> data) => FortePosSession(
    login: data['login'] as String?,
    token: data['token'] as String?,
    result: data['result'] != null ? ResultBean.fromMap(data['result'] as Map<String, dynamic>) : null,
    serverTime: data['ServerTime'] != null
        ? DateFormat("dd.MM.yyyy HH:mm:ss ZZZ").parse(data['ServerTime'])
        : null,
    tokenTimeout: data['TokenTimeout'] as int?,
  );

  Map<String, dynamic> toJson() => {
    "login": login,
    "token": token,
    "ServerTime": serverTime != null
        ? DateFormat("dd.MM.yyyy HH:mm:ss ZZZ").format(serverTime!)
        : null,
    "TokenTimeout": tokenTimeout,
    "result": result?.toJson(),
  };
}

class ResultBean {
  late String ServerTime;
  late String ResultCode;
  late String ResultStr;
  late ResponseBean? Response;

  static ResultBean? fromMap(Map<String, dynamic>? map) {
    if (map == null) return null;
    ResultBean resultBean = ResultBean();
    resultBean.ServerTime = map['ServerTime'] as String? ?? '';
    resultBean.ResultCode = map['ResultCode'] as String? ?? '';
    resultBean.ResultStr = map['ResultStr'] as String? ?? '';
    resultBean.Response = map['Response'] != null ? ResponseBean.fromMap(map['Response'] as Map<String, dynamic>) : null;
    return resultBean;
  }

  Map<String, dynamic> toJson() => {
    "ServerTime": ServerTime,
    "ResultCode": ResultCode,
    "ResultStr": ResultStr,
    "Response": Response?.toJson(),
  };
}

class ResponseBean {
  late String Code;
  late String Description;

  static ResponseBean? fromMap(Map<String, dynamic>? map) {
    if (map == null) return null;
    ResponseBean responseBean = ResponseBean();
    responseBean.Code = map['Code'] as String? ?? '';
    responseBean.Description = map['Description'] as String? ?? '';
    return responseBean;
  }

  Map<String, dynamic> toJson() => {
    "Code": Code,
    "Description": Description,
  };
}