// PIKEY Extension Firebase Configuration
const firebaseConfig = {
    apiKey: "AIzaSyBWVawzUmvNRP0U2rp2CAF5a84p633mg9I",
    authDomain: "pikey-6d982.firebaseapp.com",
    projectId: "pikey-6d982",
    storageBucket: "pikey-6d982.firebasestorage.app",
    messagingSenderId: "269931082319",
    appId: "1:269931082319:web:c4593591a27baba48bf03a"
};

// Use the same dbProvider logic for the extension
const extensionDB = {
    async getPasswords(masterPassword) {
        const db = firebase.firestore();
        // For testing we will get all, in production we would filter by UID
        // const user = firebase.auth().currentUser;
        
        const snapshot = await db.collection('passwords').get();
        const encryptedList = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
        return this.decryptBatch(encryptedList, masterPassword);
    },
    
    async decryptBatch(list, masterPassword) {
        const decrypted = [];
        for (const item of list) {
            try {
                const plainText = await PIKEY_Crypto.decrypt(item.data, masterPassword);
                decrypted.push({ id: item.id, ...JSON.parse(plainText) });
            } catch (e) { 
                console.warn("Falha ao descriptografar item:", item.id); 
            }
        }
        return decrypted;
    }
};
