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

export interface GuestRequest {
  id: number;
  booking_id: number;
  room_id: number;
  room_number?: string;
  user_id: number;
  guest_name?: string;
  guest_email?: string;
  request_type: string;
  status: string;
  priority: string;
  title: string;
  description?: string;
  guest_notes?: string;
  staff_notes?: string;
  assigned_to?: number;
  assigned_staff_name?: string;
  fulfilled_by?: number;
  fulfilled_staff_name?: string;
  requested_at: string;
  started_at?: string;
  fulfilled_at?: string;
  response_time_minutes?: number;
  fulfillment_time_minutes?: number;
}

const guestRequestService = {
  async getGuestRequests(params?: {
    status?: string;
    request_type?: string;
    room_id?: number;
    assigned_to?: number;
    priority?: string;
    page?: number;
    limit?: number;
  }) {
    const response = await apiClient.get('/guest-requests', { params });
    return response.data;
  },

  async getGuestRequest(requestId: number) {
    const response = await apiClient.get(`/guest-requests/${requestId}`);
    return response.data;
  },

  async createGuestRequest(data: {
    booking_id: number;
    room_id: number;
    request_type: string;
    title: string;
    description?: string;
    priority?: string;
    guest_notes?: string;
  }) {
    const response = await apiClient.post('/guest-requests', data);
    return response.data;
  },

  async updateGuestRequest(requestId: number, data: {
    status?: string;
    assigned_to?: number;
    staff_notes?: string;
  }) {
    const response = await apiClient.put(`/guest-requests/${requestId}`, data);
    return response.data;
  },

  async assignRequest(requestId: number) {
    const response = await apiClient.post(`/guest-requests/${requestId}/assign`);
    return response.data;
  },

  async fulfillRequest(requestId: number, staff_notes?: string) {
    const response = await apiClient.post(`/guest-requests/${requestId}/fulfill`, { staff_notes });
    return response.data;
  },
};

export default guestRequestService;

