import { callGemini } from "./geminiService"; export interface GeneratedNFT { name: string; description: string; imageUrl: string; traits: Array<{ trait_type: string; value: string | number }>; } export const nftService = { /** * Synthesizes an NFT image using Gemini 2.5 Flash Image */ generateImage: async (prompt: string): Promise => { try { const response = await callGemini( 'gemini-2.5-flash-image', { parts: [{ text: `High-fidelity digital art NFT, institutional futuristic style, 4k, cinematic lighting: ${prompt}` }], }, { imageConfig: { aspectRatio: "1:1" } } ); if (response.candidates?.[0]?.content?.parts) { for (const part of response.candidates[0].content.parts) { if (part.inlineData) { return `data:image/png;base64,${part.inlineData.data}`; } } } return null; } catch (error) { console.error("Image Synthesis Failed:", error); return null; } }, /** * Generates high-lore metadata using Gemini 3 Flash */ generateMetadata: async (imagePrompt: string): Promise> => { try { const response = await callGemini( 'gemini-3-flash-preview', `Generate a name, institutional description, and 3-4 rarity traits for an NFT based on this theme: ${imagePrompt}. Return ONLY JSON with keys: name, description, traits (array of {trait_type, value}).`, { responseMimeType: "application/json" } ); const text = response.text || '{}'; return JSON.parse(text); } catch (error) { console.error("Metadata Generation Failed:", error); return { name: "Quantum Relic", description: "An encrypted digital artifact from the Lumina Ledger.", traits: [{ trait_type: "Rarity", value: "Classified" }] }; } }, /** * Simulated OpenSea Minting sequence */ mintToOpenSea: async (nft: GeneratedNFT, openSeaKey: string, walletAddress: string) => { const steps = [ "Initializing secure tunnel to OpenSea Indexer...", `Authenticating via API Key: ${openSeaKey.substring(0, 4)}****`, "Pinning assets to IPFS (InterPlanetary File System)...", "Requesting wallet signature for contract 0x7892...B002", "Broadcasting transaction to Ethereum Mainnet...", "Waiting for block confirmation...", `Asset Indexed Successfully. TokenID: ${Math.floor(Math.random() * 100000)}` ]; return steps; } };