import TinkLink

public struct TinkLinkError: Codable {

    /// Tink's internal identifier for this specific error instance. Make sure to include the `trackingID` value when communicating with Tink to reduce time required to troubleshooting issues.
    public let trackingID: String?

    /// The identifier of the created credentials object if credentials were created
    public var credentials: String?

    /// The name of the selected bank connection if provider was selected
    public var providerName: String?

    /// The identifier of the payment request if using Payment Initiation
    public var paymentRequestID: String?

    /// A localized end-user facing error message that can be presented directly to the end user.
    public var errorDescription: String?
    
    public var errorStatus: String?
    
    var convertToString: String {
        let jsonEncoder = JSONEncoder()
        jsonEncoder.outputFormatting = .prettyPrinted
        do {
            let jsonData = try jsonEncoder.encode(self)
            if let jsonString = String(data: jsonData, encoding: .utf8) {
                return jsonString
            } else {
                return "{\"errorDescription\" : \"Something went wrong!\"}"
            }
        } catch {
            return "{\"errorDescription\" : \"Error: \(error)\"}"
        }
    }
}
