export default function Token(id, node) {
    let idTraits = {
        firstWord: "TOKEN"
    }

    let fields = [
        "index",
        "url",
        "used"
    ]

    let checkID = () => {
        let split = id.split("-")
        return (
            split[0] === idTraits.firstWord
        )
    }
    let idres = checkID()
    if(!idres) {
        return false
    }

    let checkFields = () => {
        for(let i = 0; i < fields.length; i++) {
            if(!node[fields[i]]) {
                throw new Error(`Token ${node.email} is missing trait ${fields[i]}`)
                return false
            } else {
                return true
            }
        }
    }
    let fieldres = checkFields()
    if(!fieldres) {
        return false
    }

    return true
}