/**
 * 举报服务
 * 处理帖子、评论、消息的举报功能
 */

import { api } from '../core/api';

// 举报原因类型
export type ReportReason = 'spam' | 'inappropriate' | 'harassment' | 'misinformation' | 'other';

// 举报目标类型
export type ReportTargetType = 'post' | 'comment' | 'message';

// 创建举报请求
interface CreateReportRequest {
  target_type: ReportTargetType;
  target_id: string;
  reason: ReportReason;
  description?: string;
}

// 举报响应
export interface ReportResponse {
  id: string;
  reporter_id: string;
  target_type: ReportTargetType;
  target_id: string;
  reason: ReportReason;
  description?: string;
  status: 'pending' | 'processing' | 'resolved' | 'rejected';
  created_at: string;
}

// 举报原因选项
export const REPORT_REASONS: { value: ReportReason; label: string }[] = [
  { value: 'spam', label: '垃圾广告' },
  { value: 'inappropriate', label: '违规内容' },
  { value: 'harassment', label: '辱骂/攻击' },
  { value: 'misinformation', label: '虚假信息' },
  { value: 'other', label: '其他' },
];

// 举报服务类
class ReportService {
  /**
   * 创建举报
   * @param targetType 举报目标类型
   * @param targetId 目标ID
   * @param reason 举报原因
   * @param description 详细描述（可选）
   */
  async createReport(
    targetType: ReportTargetType,
    targetId: string,
    reason: ReportReason,
    description?: string
  ): Promise<ReportResponse | null> {
    try {
      const request: CreateReportRequest = {
        target_type: targetType,
        target_id: targetId,
        reason,
        description,
      };
      const response = await api.post<ReportResponse>('/reports', request);
      return response.data;
    } catch (error) {
      console.error('创建举报失败:', error);
      return null;
    }
  }

  /**
   * 获取举报原因标签
   */
  getReasonLabel(reason: ReportReason): string {
    const item = REPORT_REASONS.find(r => r.value === reason);
    return item?.label ?? reason;
  }
}

export const reportService = new ReportService();
export default reportService;
