import { javaPost } from './apiClient';

/** What kind of record the message is attached to. */
export type UserMessageType = 'alkotas'; // officially BE currently accepts any string, we only work with 'alkotas' for now

export interface UserMessageDto {
  /** identifier of the record the message belongs to (e.g. a creation's azonosító) */
  rowId: number | string;
  messageType: UserMessageType;
  email: string;
  message: string;
}

/**
 * Sends a public contribution / correction message for a record.
 * Backend: userMessageControl/save — wraps the payload in a `dto` envelope.
 */
export async function saveUserMessage(dto: UserMessageDto): Promise<boolean> {
  try {
    const response = await javaPost('userMessageControl/save', { dto });
    return Boolean(response);
  } catch (error) {
    console.error('Error saving user message:', error);
    return false;
  }
}
