import apiClient from '../../../shared/services/apiClient';

export interface Complaint {
  id: number;
  guest_id: number;
  guest_name?: string;
  booking_id?: number;
  room_id?: number;
  room_number?: string;
  category: string;
  priority: string;
  status: string;
  title: string;
  description: string;
  attachments?: string[];
  assigned_to?: number;
  assigned_staff_name?: string;
  resolved_at?: string;
  resolution_notes?: string;
  created_at: string;
  updated_at: string;
}

export interface ComplaintUpdate {
  id: number;
  complaint_id: number;
  update_type: string;
  description: string;
  updated_by: number;
  updated_by_name?: string;
  created_at: string;
}

const complaintService = {
  async getComplaints(params?: {
    status?: string;
    priority?: string;
    category?: string;
    assigned_to?: number;
    page?: number;
    limit?: number;
  }) {
    const response = await apiClient.get('/complaints', { params });
    return response.data;
  },

  async getComplaint(complaintId: number) {
    const response = await apiClient.get(`/complaints/${complaintId}`);
    return response.data;
  },

  async updateComplaint(complaintId: number, data: {
    status?: string;
    priority?: string;
    assigned_to?: number;
    resolution_notes?: string;
  }) {
    const response = await apiClient.put(`/complaints/${complaintId}`, data);
    return response.data;
  },

  async resolveComplaint(complaintId: number, data: {
    resolution_notes: string;
    compensation_amount?: number;
  }) {
    const response = await apiClient.post(`/complaints/${complaintId}/resolve`, data);
    return response.data;
  },

  async addComplaintUpdate(complaintId: number, data: {
    description: string;
    update_type?: string;
  }) {
    const response = await apiClient.post(`/complaints/${complaintId}/updates`, data);
    return response.data;
  },
};

export default complaintService;

