import { SESv2Client, SendEmailCommand, GetAccountCommand } from '@aws-sdk/client-sesv2';
export function createSesClient(config) {
    const configured = !!(config.accessKeyId && config.secretAccessKey);
    const client = configured
        ? new SESv2Client({
            region: config.region,
            credentials: { accessKeyId: config.accessKeyId, secretAccessKey: config.secretAccessKey },
        })
        : null;
    return {
        isConfigured: () => configured,
        async sendEmail(params) {
            if (!client)
                throw new Error('SES not configured');
            const cmd = new SendEmailCommand({
                FromEmailAddress: `${params.fromName} <${params.from}>`,
                Destination: { ToAddresses: [params.to] },
                Content: {
                    Simple: {
                        Subject: { Data: params.subject, Charset: 'UTF-8' },
                        Body: {
                            Html: { Data: params.htmlBody, Charset: 'UTF-8' },
                            Text: { Data: params.textBody, Charset: 'UTF-8' },
                        },
                    },
                },
            });
            const res = await client.send(cmd);
            return { messageId: res.MessageId ?? '' };
        },
        async getSendQuota() {
            if (!client)
                throw new Error('SES not configured');
            const res = await client.send(new GetAccountCommand({}));
            const q = res.SendQuota ?? {};
            return {
                maxSendRate: q.MaxSendRate ?? 1,
                max24HourSend: q.Max24HourSend ?? 0,
                sentLast24Hours: q.SentLast24Hours ?? 0,
            };
        },
    };
}
//# sourceMappingURL=ses-client.js.map