/**
 * Public Contact API Service
 * Handles public form submissions (contact, feedback, prelaunch)
 * These endpoints don't require authentication
 */

import axios from 'axios';
import { getApiUrl } from '../../config/runtime';

const publicApiClient = axios.create({
  baseURL: getApiUrl(),
  timeout: 30000,
  headers: {
    'Content-Type': 'application/json',
  },
});

// Types
export interface ContactFormData {
  name: string;
  email: string;
  phone?: string;
  bakery_name?: string;
  type: 'general' | 'technical' | 'sales' | 'feedback';
  subject: string;
  message: string;
}

export interface FeedbackFormData {
  name: string;
  email: string;
  category: 'suggestion' | 'bug' | 'feature' | 'praise' | 'complaint';
  title: string;
  description: string;
  rating?: number;
}

export interface PrelaunchEmailData {
  email: string;
}

export interface ContactFormResponse {
  success: boolean;
  message: string;
}

// API Functions
export const publicContactService = {
  /**
   * Submit a contact form
   */
  submitContactForm: async (data: ContactFormData): Promise<ContactFormResponse> => {
    const response = await publicApiClient.post<ContactFormResponse>(
      '/v1/public/contact',
      data
    );
    return response.data;
  },

  /**
   * Submit a feedback form
   */
  submitFeedbackForm: async (data: FeedbackFormData): Promise<ContactFormResponse> => {
    const response = await publicApiClient.post<ContactFormResponse>(
      '/v1/public/feedback',
      data
    );
    return response.data;
  },

  /**
   * Submit a prelaunch email subscription
   */
  submitPrelaunchEmail: async (data: PrelaunchEmailData): Promise<ContactFormResponse> => {
    const response = await publicApiClient.post<ContactFormResponse>(
      '/v1/public/prelaunch-subscribe',
      data
    );
    return response.data;
  },
};

export default publicContactService;
