import { SQSClient, SendMessageCommand, SendMessageCommandInput } from "@aws-sdk/client-sqs";
import { v4 as uuid } from "uuid";
import { SqsConfig } from "./sqs.config";

const client: SQSClient = new SQSClient(
    {
        region: SqsConfig.region,
        endpoint: SqsConfig.endpoint,
        credentials: SqsConfig.credentials,
    }
);

const params: SendMessageCommandInput = {
    // DelaySeconds: 10, // remove when non FIFO
    MessageAttributes: {
        Title: {
            DataType: "String",
            StringValue: "Test message",
        },
        Author: {
            DataType: "String",
            StringValue: "Michal Adamski",
        },
        SomeNumberAttribute: {
            DataType: "Number",
            StringValue: "6",
        },
    },
    MessageBody: "This is test message body for Engage SaySimple project",
    MessageDeduplicationId: uuid(),  // Required for FIFO queues
    MessageGroupId: "Group1",  // Required for FIFO queues
    QueueUrl: `${SqsConfig.endpoint}/${SqsConfig.accountId}/${SqsConfig.queueName}` //SQS_QUEUE_URL; e.g., 'https://sqs.REGION.amazonaws.com/ACCOUNT-ID/QUEUE-NAME'
};

const command: SendMessageCommand = new SendMessageCommand(params);


client.send(command).then((response) => {
    console.log(response);
}).catch((error) => {
    console.error(error);
});