import { PrismaClient } from '@prisma/client';
import { v4 as uuidv4 } from 'uuid';

const prisma = new PrismaClient();

export interface FeedbackInput {
  type: 'suggestion' | 'bug' | 'other';
  title: string;
  content: string;
  contact?: string;
  screenshotUrls?: string[];
}

export interface FeedbackResult {
  id: string;
  status: 'submitted';
}

export const feedbackService = {
  /**
   * 提交反馈
   */
  async submitFeedback(input: FeedbackInput): Promise<FeedbackResult> {
    const id = uuidv4();

    await prisma.feedback.create({
      data: {
        id,
        type: input.type,
        title: input.title,
        content: input.content,
        contact: input.contact || '',
        screenshotUrls: JSON.stringify(input.screenshotUrls || []),
        status: 'submitted',
      },
    });

    return { id, status: 'submitted' };
  },
};