import 'package:syncrow_web/utils/constants/app_enum.dart';

class PasswordModel {
  final dynamic passwordId;
  final dynamic invalidTime;
  final dynamic effectiveTime;
  final dynamic passwordCreated;
  final dynamic createdTime;
  final dynamic passwordName;
  final AccessStatus passwordStatus;
  final AccessType passwordType;
  final dynamic deviceUuid;
  final dynamic authorizerEmail;
  final dynamic authorizerDate;
  final dynamic deviceName;

  PasswordModel({
    this.passwordId,
    this.invalidTime,
    this.effectiveTime,
    this.passwordCreated,
    this.createdTime,
    this.passwordName,
    required this.passwordStatus,
    required this.passwordType,
    this.deviceUuid,
    this.authorizerEmail,
    this.authorizerDate,
    this.deviceName,
  });

  factory PasswordModel.fromJson(Map<String, dynamic> json) {
    return PasswordModel(
      passwordId: json['passwordId'],
      invalidTime: json['invalidTime'],
      effectiveTime: json['effectiveTime'],
      passwordCreated: json['passwordCreated'],
      createdTime: json['createdTime'],
      passwordName: json['passwordName']??'No Name',
      passwordStatus: AccessStatusExtension.fromString(json['passwordStatus']),
      passwordType: AccessTypeExtension.fromString(json['passwordType']),
      deviceUuid: json['deviceUuid'],
      authorizerEmail: json['authorizerEmail'],
      authorizerDate: json['authorizerDate'],
      deviceName: json['deviceName'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'passwordId': passwordId,
      'invalidTime': invalidTime,
      'effectiveTime': effectiveTime,
      'passwordCreated': passwordCreated,
      'createdTime': createdTime,
      'passwordName': passwordName, // New field
      'passwordStatus': passwordStatus,
      'passwordType': passwordType,
      'deviceUuid': deviceUuid,
      'authorizerEmail': authorizerEmail,
      'authorizerDate': authorizerDate,
      'deviceName': deviceName,
    };
  }
}
