import { BaseCommand } from '@adonisjs/core/ace';
export default class DebugHash extends BaseCommand {
    static commandName = 'debug:hash';
    static description = 'Debug hashing and DB storage';
    static options = {
        startApp: true,
    };
    async run() {
        const { default: hash } = await import('@adonisjs/core/services/hash');
        const { default: User } = await import('#models/user');
        const { default: db } = await import('@adonisjs/lucid/services/db');
        console.log('--- Starting Hash Debug ---');
        const password = 'admin123';
        const hashed = await hash.make(password);
        console.log(`Original Password: ${password}`);
        console.log(`Generated Hash (len=${hashed.length}): ${hashed}`);
        const verifyImmediate = await hash.verify(hashed, password);
        console.log(`Immediate Verify: ${verifyImmediate}`);
        const email = 'admin@portfolio.local';
        const user = await User.findBy('email', email);
        if (user) {
            console.log(`\nUpdating user ${user.id} with new hash via RAW DB...`);
            await db.from('users').where('id', user.id).update({ password: hashed });
            const userReloaded = await User.find(user.id);
            if (!userReloaded)
                return;
            console.log(`Reloaded Model Hash (len=${userReloaded.password.length}): ${userReloaded.password}`);
            if (userReloaded.password !== hashed) {
                console.error('MISMATCH! storage altered the hash.');
                console.error(`Expected: ${hashed}`);
                console.error(`Actual:   ${userReloaded.password}`);
            }
            else {
                console.log('MATCH! Storage preserved the hash.');
            }
            const verifyModel = await hash.verify(userReloaded.password, password);
            console.log(`Model Verify: ${verifyModel}`);
            const rawUser = await db.from('users').where('id', user.id).first();
            console.log(`Raw DB Hash (len=${rawUser.password.length}): ${rawUser.password}`);
            if (rawUser.password !== hashed) {
                console.error('MISMATCH in Raw DB!');
            }
        }
        else {
            console.error('User not found!');
        }
    }
}
//# sourceMappingURL=debug_hash.js.map