import { requestClient } from '#/api/request';

export namespace TelegramApi {
  export interface NotificationConfig {
    id: number;
    name: string;
    botToken: string;
    chatId: string;
    notificationTypes: string[];
    isEnabled: boolean;
    createdAt: string;
    updatedAt: string;
  }

  export interface CreateNotificationConfigParams {
    name: string;
    botToken: string;
    chatId: string;
    notificationTypes?: string[];
    isEnabled?: boolean;
  }

  export interface UpdateNotificationConfigParams {
    name?: string;
    botToken?: string;
    chatId?: string;
    notificationTypes?: string[];
    isEnabled?: boolean;
  }

  export interface TestNotificationConfigParams {
    botToken: string;
    chatId: string;
  }
}

export function getTelegramNotificationConfigs() {
  return requestClient.get<TelegramApi.NotificationConfig[]>(
    '/telegram/notifications',
  );
}

export function createTelegramNotificationConfig(
  data: TelegramApi.CreateNotificationConfigParams,
) {
  return requestClient.post<TelegramApi.NotificationConfig>(
    '/telegram/notifications',
    data,
  );
}

export function updateTelegramNotificationConfig(
  id: number,
  data: TelegramApi.UpdateNotificationConfigParams,
) {
  return requestClient.put<TelegramApi.NotificationConfig>(
    `/telegram/notifications/${id}`,
    data,
  );
}

export function deleteTelegramNotificationConfig(id: number) {
  return requestClient.delete<{ id: number }>(`/telegram/notifications/${id}`);
}

export function testTelegramNotificationConfig(
  data: TelegramApi.TestNotificationConfigParams,
) {
  return requestClient.post<{ message: string }>('/telegram/test', data);
}
