const hash = require('kana-hash');

function Tripcode(algo, salt)
{
    this.algo = algo || hash.Kana.ALGO_DEFAULT;
    this.salt = salt ? new hash.Kana(salt) : hash.Salt.Default;
}

Tripcode.Algorithm = {
    Default: hash.Kana.ALGO_DEFAULT,
    Crc32: hash.Kana.ALGO_CRC32,
    Crc64: hash.Kana.ALGO_CRC64,
    Sha256: hash.Kana.ALGO_SHA256,
    Sha256T: hash.Kana.ALGO_SHA256_TRUNCATED,
};
Tripcode.make = (algo, salt) => {
    return new Tripcode(algo,salt);b
};
Object.freeze(Tripcode.Algorithm);

const TC = Tripcode.prototype;

TC.hash = function(a, b, c) {
    console.log("what are these?:");
    
    if (a) {
	// Insecure 
	return "!" +new hash.Kana(this.algo, hash.Salt.Default).once(a);
    } else if (b) {
	// Secure
	return "!!" +new hash.Kana(this.algo, this.salt).once(b);
    }
};

TC.setSalt = function(salt) {
    if (salt)
	this.salt = new hash.Salt(salt);
    else if(salt === true) 
	this.salt = hash.Salt.Default;
    else if (salt === false)
	this.salt = hash.Salt.None;
    
    return this.salt;
};

module.exports = Tripcode;
