import * as grpc from '@grpc/grpc-js';
import { kordProto } from '@kord/grpc-contracts';

const BOT_GRPC_URL = process.env.BOT_GRPC_URL || '127.0.0.1:50051';

export const botClient = new (kordProto as any).BotDashboardService(
  BOT_GRPC_URL,
  grpc.credentials.createInsecure()
);

export const pingBot = (message: string): Promise<{ reply: string }> => {
  return new Promise((resolve, reject) => {
    botClient.Ping({ message }, (err: any, response: any) => {
      if (err) {
        reject(err);
      } else {
        resolve(response);
      }
    });
  });
};

export const getGuildChannels = (guildId: string): Promise<any> => {
  return new Promise((resolve, reject) => {
    botClient.GetGuildChannels({ guildId }, (err: any, response: any) => {
      if (err) {
        reject(err);
      } else {
        resolve(response.channels);
      }
    });
  });
};
