File size: 3,294 Bytes
333c51a
 
30ad7ef
333c51a
30ad7ef
 
 
 
 
333c51a
 
 
 
 
 
 
 
30ad7ef
 
 
333c51a
30ad7ef
 
 
 
333c51a
 
 
 
 
 
30ad7ef
333c51a
 
 
 
30ad7ef
 
 
333c51a
 
30ad7ef
333c51a
30ad7ef
 
 
333c51a
30ad7ef
 
 
333c51a
 
 
 
 
 
30ad7ef
333c51a
30ad7ef
333c51a
30ad7ef
 
 
333c51a
 
30ad7ef
 
 
333c51a
30ad7ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { NextRequest, NextResponse } from "next/server";
import ZAI from "z-ai-web-dev-sdk";
import { db } from "@/lib/db";

const FAMOUS_INFLUENCERS = [
  { name: "Lil Miquela", handle: "@lilmiquela", platform: "Instagram", followers: 2500000, engagement: 3.2, niche: "Fashion", petCompanion: false, lessons: ["Consistencia visual", "Narrativa creible"] },
  { name: "Rozy", handle: "@rozy.gram", platform: "Instagram", followers: 180000, engagement: 4.5, niche: "K-pop", petCompanion: true, petType: "dog", lessons: ["Tendencias K-pop", "Mascota como diferenciador"] },
  { name: "Imma", handle: "@imma.gram", platform: "Instagram", followers: 390000, engagement: 3.8, niche: "Fashion & Art", petCompanion: false, lessons: ["Fusionar arte y moda"] },
  { name: "Ayla", handle: "@ayla_virtual", platform: "TikTok", followers: 850000, engagement: 8.3, niche: "Dance", petCompanion: true, petType: "dog", lessons: ["Participar en trends", "Alta frecuencia"] }
];

export async function GET(request: NextRequest) {
  try {
    const { searchParams } = new URL(request.url);
    const niche = searchParams.get("niche");
    const withPets = searchParams.get("withPets");

    let influencers = [...FAMOUS_INFLUENCERS];
    if (niche) influencers = influencers.filter(i => i.niche.toLowerCase().includes(niche.toLowerCase()));
    if (withPets === "true") influencers = influencers.filter(i => i.petCompanion);

    const dbInfluencers = await db.aIInfluencer.findMany({ where: { isActive: true } });
    return NextResponse.json({ success: true, influencers, customInfluencers: dbInfluencers });
  } catch {
    return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
  }
}

export async function POST(request: NextRequest) {
  try {
    const body = await request.json();
    const { targetNiche, includePets } = body;

    const zai = await ZAI.create();
    const completion = await zai.chat.completions.create({
      messages: [
        { role: "system", content: "Eres experto en marketing de influencers. Responde JSON con {contentPatterns:[], visualStyles:[], recommendations:[]}" },
        { role: "user", content: "Analiza estrategias para nicho: " + (targetNiche || "general") }
      ]
    });

    let analysis: Record<string, unknown[]> = {};
    try {
      const match = completion.choices[0]?.message?.content?.match(/\{[\s\S]*\}/);
      if (match) analysis = JSON.parse(match[0]);
    } catch {}

    return NextResponse.json({ success: true, influencers: FAMOUS_INFLUENCERS.slice(0, 4), analysis });
  } catch {
    return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
  }
}

export async function PUT(request: NextRequest) {
  try {
    const body = await request.json();
    const { name, handle, platform, followers, engagement, niche, petCompanion, petType } = body;

    const influencer = await db.aIInfluencer.create({
      data: {
        name, handle: handle || null, platform, followers: followers || null,
        engagement: engagement || null, niche: niche || null,
        petCompanion: petCompanion || false, petType: petType || null
      }
    });
    return NextResponse.json({ success: true, influencer });
  } catch {
    return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
  }
}