import apiClient from "@/lib/axiosClient";
import { API_ENDPOINTS } from "@/lib/apiEndpoints";

export interface RawGift {
  id: number;
  name: string;
  storage_type: number;
  image: string;
  price: number;
  status: number;
  is_buy: number;
}

export interface Gift {
  id: number;
  name: string;
  image: string;
  price: number;
}

export interface SendGiftParams {
  gift_id: number;
  channel_id: string;
  content_id: string;
  price: number;
}

export const giftService = {
  getGifts: async (): Promise<Gift[]> => {
    const res = await apiClient.post(API_ENDPOINTS.GIFT.GET);
    const raw: RawGift[] = res.data?.result ?? [];
    return raw
      .filter((g) => g.status === 1)
      .map((g) => ({ id: g.id, name: g.name, image: g.image, price: g.price }));
  },

  sendGift: (params: SendGiftParams): Promise<{ status: number; message: string }> =>
    apiClient
      .post(API_ENDPOINTS.GIFT.SEND, {
        gift_id:    params.gift_id,
        channel_id: params.channel_id,
        content_id: params.content_id,
        price:      params.price,
      })
      .then((r) => r.data),
};
