<commit_before>//
//  PhoneNumber.swift
//  PhoneNumberKit
//
//  Created by <NAME> on 26/09/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

/**
Parsed phone number object
 
- CountryCode: Country dialing code as an unsigned. Int.
- LeadingZero: Some countries (e.g. Italy) require leading zeros. Bool.
- NationalNumber: National number as an unsigned. Int.
- NumberExtension: Extension if available. String. Optional
- RawNumber: String used to generate phone number struct
- Type: Computed phone number type on access. Returns from an enumeration - PNPhoneNumberType.
*/
public struct PhoneNumber {
    public let numberString: String
    public let countryCode: UInt64
    public let leadingZero: Bool
    public let nationalNumber: UInt64
    public let numberExtension: String?
    public let type: PhoneNumberType
}

/// In past versions of PhoneNumebrKit you were able to initialize a PhoneNumber object to parse a String. Please use a PhoneNumberKit object's methods.
public extension PhoneNumber {
    /**
    DEPRECATED. 
    Parse a string into a phone number object using default region. Can throw.
    - Parameter rawNumber: String to be parsed to phone number struct.
    */
    @available(*, unavailable, message: "use PhoneNumberKit instead to produce PhoneNumbers")
    public init(rawNumber: String) throws {
        assertionFailure(PhoneNumberError.deprecated.description)
        throw PhoneNumberError.deprecated
    }
    
    /**<commit_msg>Adopt `Equatable` and `Hashable` by `PhoneNumber`.<commit_after>//
//  PhoneNumber.swift
//  PhoneNumberKit
//
//  Created by <NAME> on 26/09/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

/**
Parsed phone number object
 
- CountryCode: Country dialing code as an unsigned. Int.
- LeadingZero: Some countries (e.g. Italy) require leading zeros. Bool.
- NationalNumber: National number as an unsigned. Int.
- NumberExtension: Extension if available. String. Optional
- RawNumber: String used to generate phone number struct
- Type: Computed phone number type on access. Returns from an enumeration - PNPhoneNumberType.
*/
public struct PhoneNumber {
    public let numberString: String
    public let countryCode: UInt64
    public let leadingZero: Bool
    public let nationalNumber: UInt64
    public let numberExtension: String?
    public let type: PhoneNumberType
}

extension PhoneNumber : Equatable {

    public static func ==(lhs: PhoneNumber, rhs: PhoneNumber) -> Bool {
        return (lhs.countryCode == rhs.countryCode)
            && (lhs.leadingZero == rhs.leadingZero)
            && (lhs.nationalNumber == rhs.nationalNumber)
            && (lhs.numberExtension == rhs.numberExtension)
    }

}

extension PhoneNumber : Hashable {

    public var hashValue: Int {
        var hashValue = 0

        hashValue ^= Int(truncatingBitPattern: countryCode)
        hashValue ^= Int(truncatingBitPattern: nationalNumber)

        if MemoryLayout<Int>.size != MemoryLayout<Int64>.size {
            // On 32-bit arch, `nationalNumber` doesn't fit `Int`, and to calculate hash,
            // we need to shift the most significant bits.
            hashValue ^= Int(truncatingBitPattern: nationalNumber >> 32)
        }

        if let numberExtension = numberExtension {
            hashValue ^= numberExtension.hashValue
        }

        return hashValue
    }

}

/// In past versions of PhoneNumebrKit you were able to initialize a PhoneNumber object to parse a String. Please use a PhoneNumberKit object's methods.
public extension PhoneNumber {
    /**
    DEPRECATED. 
    Parse a string into a phone number object using default region. Can throw.
    - Parameter rawNumber: String to be parsed to phone number struct.
    */
    @available(*, unavailable, message: "use PhoneNumberKit instead to produce PhoneNumbers")
    public init(rawNumber: String) throws {
        assertionFailure(PhoneNumberError.deprecated.description)
        throw PhoneNumberError.deprecated
    }
    
    /**
{'fraction_non_alphanumeric': 0.08006941001487357, 'fraction_numerical': 0.009667823500247892, 'mean_word_length': 3.1131498470948014, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5373241', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1038, 'n_words': 403}