File size: 10,235 Bytes
333c51a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
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 }
    );
  }
}