import 'package:autos/domain/entities/turn14.dart';
class Turn14StatusModel {
  final String userId;
  final bool hasCredentials;
  final String? clientId;
  final String? clientSecret;
  final String? accessToken;
  final String? expiresIn;
  final String? code;
  final String? message;

  Turn14StatusModel({
    required this.userId,
    required this.hasCredentials,
    this.clientId,
    this.clientSecret,
    this.accessToken,
    this.expiresIn,
    this.code,
    this.message,
  });

  factory Turn14StatusModel.fromJson(Map<String, dynamic> json) {
    final credentials = json["credentials"];
    final tokenInfo = json["tokenInfo"];

    return Turn14StatusModel(
      userId: json["userid"]?.toString() ?? "",
      hasCredentials: json["hasCredentials"] ?? false,
      clientId: credentials?["turn14clientid"],
      clientSecret: credentials?["turn14clientsecret"],
      accessToken: tokenInfo?["access_token"],
      expiresIn: tokenInfo?["expires_in"]?.toString(),
      code: json["code"],
      message: json["message"],
    );
  }

  Map<String, dynamic> toJson() => {
        "userid": userId,
        "hasCredentials": hasCredentials,
        "credentials": {
          "turn14clientid": clientId,
          "turn14clientsecret": clientSecret,
        },
        "tokenInfo": {
          "access_token": accessToken,
          "expires_in": expiresIn,
        },
        "code": code,
        "message": message,
      };

  Turn14Entity toEntity() {
    return Turn14Entity(
      code: code ?? '',
      message: message ?? '',
      userId: userId,
      hasCredentials: hasCredentials,
      clientId: clientId,
      clientSecret: clientSecret,
      accessToken: accessToken,
      expiresIn: expiresIn,
    );
  }
}
