import {
  SNSClient,
  PublishCommand,
  PublishCommandInput,
  PublishCommandOutput,
} from "@aws-sdk/client-sns";

const snsClient = new SNSClient({ region: process.env.AWS_REGION });

/**
 * Envía un SMS a un número de teléfono.
 */
export async function sendSMS(
  phoneNumber: string,
  message: string,
  options?: Omit<PublishCommandInput, "PhoneNumber" | "Message">
): Promise<PublishCommandOutput> {
  const params: PublishCommandInput = {
    PhoneNumber: phoneNumber,
    Message: message,
    ...options,
  };
  const command = new PublishCommand(params);
  return snsClient.send(command);
}

/**
 * Publica un mensaje en un topic SNS.
 */
export async function publishTopic(
  topicArn: string,
  message: string,
  options?: Omit<PublishCommandInput, "TopicArn" | "Message">
): Promise<PublishCommandOutput> {
  const params: PublishCommandInput = {
    TopicArn: topicArn,
    Message: message,
    ...options,
  };
  const command = new PublishCommand(params);
  return snsClient.send(command);
}
