import { NextRequest, NextResponse } from "next/server"; import { db } from "@/lib/db"; // Configuración legal de cada plataforma const PLATFORM_CONFIGS = { onlyfans: { name: "OnlyFans", type: "subscription", url: "https://onlyfans.com", feePercentage: 20, legalTerms: { ageRequirement: 18, contentTypes: ["adult", "lifestyle", "fitness", "art"], prohibitedContent: ["illegal content", "non-consensual", "underage"], verificationRequired: true, taxReporting: true, payoutSchedule: "weekly" }, contentRules: { adultContent: "allowed", nudity: "allowed", explicit: "allowed_with_verification", copyright: "must_own_or_license" } }, patreon: { name: "Patreon", type: "subscription", url: "https://patreon.com", feePercentage: 12, legalTerms: { ageRequirement: 18, contentTypes: ["art", "music", "podcasts", "videos", "writing", "gaming"], prohibitedContent: ["adult content with real people", "hate speech", "illegal content"], verificationRequired: true, taxReporting: true, payoutSchedule: "monthly" }, contentRules: { adultContent: "restricted", nudity: "allowed_with_warning", explicit: "not_allowed", copyright: "must_own_or_license" } }, fansly: { name: "Fansly", type: "mixed", url: "https://fansly.com", feePercentage: 20, legalTerms: { ageRequirement: 18, contentTypes: ["adult", "lifestyle", "creator"], prohibitedContent: ["illegal content", "non-consensual", "underage"], verificationRequired: true, taxReporting: true, payoutSchedule: "weekly" }, contentRules: { adultContent: "allowed", nudity: "allowed", explicit: "allowed_with_verification", copyright: "must_own_or_license" } }, fanvue: { name: "Fanvue", type: "subscription", url: "https://fanvue.com", feePercentage: 15, legalTerms: { ageRequirement: 18, contentTypes: ["adult", "fitness", "lifestyle", "music", "art"], prohibitedContent: ["illegal content", "non-consensual", "underage"], verificationRequired: true, taxReporting: true, payoutSchedule: "weekly" }, contentRules: { adultContent: "allowed", nudity: "allowed", explicit: "allowed_with_verification", copyright: "must_own_or_license" } }, justforfans: { name: "JustForFans", type: "mixed", url: "https://justfor.fans", feePercentage: 20, legalTerms: { ageRequirement: 18, contentTypes: ["adult"], prohibitedContent: ["illegal content", "non-consensual", "underage"], verificationRequired: true, taxReporting: true, payoutSchedule: "weekly" }, contentRules: { adultContent: "allowed", nudity: "allowed", explicit: "allowed_with_verification", copyright: "must_own_or_license" } }, kofi: { name: "Ko-fi", type: "tips", url: "https://ko-fi.com", feePercentage: 0, legalTerms: { ageRequirement: 13, contentTypes: ["art", "commissions", "digital products", "memberships"], prohibitedContent: ["adult content", "illegal content", "hate speech"], verificationRequired: false, taxReporting: false, payoutSchedule: "instant" }, contentRules: { adultContent: "not_allowed", nudity: "not_allowed", explicit: "not_allowed", copyright: "must_own_or_license" } }, gumroad: { name: "Gumroad", type: "ppv", url: "https://gumroad.com", feePercentage: 10, legalTerms: { ageRequirement: 13, contentTypes: ["digital products", "courses", "memberships", "software"], prohibitedContent: ["illegal content", "hate speech"], verificationRequired: false, taxReporting: true, payoutSchedule: "weekly" }, contentRules: { adultContent: "restricted", nudity: "allowed_with_warning", explicit: "not_allowed", copyright: "must_own_or_license" } }, instagram: { name: "Instagram", type: "free", url: "https://instagram.com", feePercentage: 0, legalTerms: { ageRequirement: 13, contentTypes: ["photos", "reels", "stories", "lives"], prohibitedContent: ["nudity", "violence", "hate speech", "illegal content"], verificationRequired: false, taxReporting: false, payoutSchedule: "none" }, contentRules: { adultContent: "not_allowed", nudity: "not_allowed", explicit: "not_allowed", copyright: "must_own_or_license" } }, tiktok: { name: "TikTok", type: "free", url: "https://tiktok.com", feePercentage: 0, legalTerms: { ageRequirement: 13, contentTypes: ["short videos", "live"], prohibitedContent: ["nudity", "violence", "dangerous acts", "hate speech"], verificationRequired: false, taxReporting: false, payoutSchedule: "none" }, contentRules: { adultContent: "not_allowed", nudity: "not_allowed", explicit: "not_allowed", copyright: "must_own_or_license" } }, youtube: { name: "YouTube", type: "ad_revenue", url: "https://youtube.com", feePercentage: 45, // YouTube toma 45% de ad revenue legalTerms: { ageRequirement: 13, contentTypes: ["videos", "shorts", "live", "community"], prohibitedContent: ["nudity", "violence", "hate speech", "copyright violation"], verificationRequired: true, taxReporting: true, payoutSchedule: "monthly" }, contentRules: { adultContent: "not_allowed", nudity: "not_allowed", explicit: "not_allowed", copyright: "strict_enforcement" } } }; // GET - Listar plataformas disponibles export async function GET(request: NextRequest) { try { const { searchParams } = new URL(request.url); const type = searchParams.get("type"); // subscription, tips, ppv, free // Obtener plataformas configuradas por el usuario const userPlatforms = await db.monetizationPlatform.findMany({ include: { _count: { select: { posts: true, earnings: true, subscribers: true } } }, orderBy: { createdAt: "desc" } }); // Filtrar por tipo si se especifica let availablePlatforms = Object.entries(PLATFORM_CONFIGS).map(([key, config]) => ({ id: key, ...config })); if (type) { availablePlatforms = availablePlatforms.filter(p => p.type === type); } return NextResponse.json({ success: true, userPlatforms, availablePlatforms, totalUserPlatforms: userPlatforms.length }); } catch (error) { console.error("Error fetching monetization platforms:", error); return NextResponse.json( { success: false, error: "Error al obtener plataformas" }, { status: 500 } ); } } // POST - Añadir/configurar plataforma export async function POST(request: NextRequest) { try { const body = await request.json(); const { platformKey, accountId, accountName, apiKey, isVerified } = body; if (!platformKey || !PLATFORM_CONFIGS[platformKey as keyof typeof PLATFORM_CONFIGS]) { return NextResponse.json( { success: false, error: "Plataforma no válida" }, { status: 400 } ); } const config = PLATFORM_CONFIGS[platformKey as keyof typeof PLATFORM_CONFIGS]; // Crear o actualizar plataforma const platform = await db.monetizationPlatform.create({ data: { name: config.name, type: config.type, url: config.url, apiKey: apiKey || null, accountId: accountId || null, accountName: accountName || null, legalTerms: JSON.stringify(config.legalTerms), contentRules: JSON.stringify(config.contentRules), feePercentage: config.feePercentage, payoutSchedule: config.legalTerms.payoutSchedule, isVerified: isVerified || false, } }); return NextResponse.json({ success: true, platform, legalInfo: config.legalTerms, contentRules: config.contentRules, message: `Plataforma ${config.name} configurada` }); } catch (error) { console.error("Error creating platform:", error); return NextResponse.json( { success: false, error: "Error al configurar plataforma" }, { status: 500 } ); } } // PUT - Actualizar plataforma export async function PUT(request: NextRequest) { try { const body = await request.json(); const { id, accountId, accountName, apiKey, isVerified, isActive } = body; if (!id) { return NextResponse.json( { success: false, error: "ID de plataforma requerido" }, { status: 400 } ); } const platform = await db.monetizationPlatform.update({ where: { id }, data: { accountId: accountId || undefined, accountName: accountName || undefined, apiKey: apiKey || undefined, isVerified: isVerified || undefined, isActive: isActive !== undefined ? isActive : undefined, } }); return NextResponse.json({ success: true, platform }); } catch (error) { console.error("Error updating platform:", error); return NextResponse.json( { success: false, error: "Error al actualizar plataforma" }, { status: 500 } ); } } // DELETE - Eliminar plataforma export async function DELETE(request: NextRequest) { try { const { searchParams } = new URL(request.url); const id = searchParams.get("id"); if (!id) { return NextResponse.json( { success: false, error: "ID requerido" }, { status: 400 } ); } await db.monetizationPlatform.delete({ where: { id } }); return NextResponse.json({ success: true, message: "Plataforma eliminada" }); } catch (error) { console.error("Error deleting platform:", error); return NextResponse.json( { success: false, error: "Error al eliminar plataforma" }, { status: 500 } ); } }