"use server"
import { sendEmails } from "@/lib/mail.utils"
import { NextRequest, NextResponse } from "next/server"

export async function POST(request: NextRequest) {
    const sender = {
        name: 'Kevos Official',
        address: 'no-reply@kevosattire.com',
    }

    const recipients = [{
        name: 'Fernando Delgado',
        address: 'kevosattire@gmail.com',
    }]

    const clientEmail = await request.json();

    try{
        const result = await sendEmails({
            sender,
            recipients,
            subject: "New Order!",
            message: `New order from ${clientEmail.senderEmail}`
        })

        return NextResponse.json({
            accepted: result.accepted,
        })
    } catch (error){
        return NextResponse.json({message: 'Unable to send email at this time.'}, {status: 500})
    }
}

// export async function GET(req: NextRequest){
//     return NextResponse.json({message: 'Hello'})
// }