<?php
namespace App\Services;

use Illuminate\Support\Facades\Mail;
use App\Mail\InquiryMail;

class MailService
{
    /**
     * 发送询盘邮件（静态方法）
     *
     * @param array $inquiryData 询盘数据
     * @return bool 返回是否发送成功
     */
    public static function sendInquiryMail(array $inquiryData)
    {
        try {
            $toAddress = config('mail_recipients.to.address');
            $ccAddress = config('mail_recipients.cc.address');

            if (empty($toAddress)) {
                // 没有收件人地址时，记录日志并返回 false
                logger()->warning('邮件未发送：缺少收件人地址');
                return false;
            }

            $mail = Mail::to($toAddress);

            if (!empty($ccAddress)) {
                $mail->cc($ccAddress);
            }

            $mail->send(new InquiryMail($inquiryData));

            return true; // 成功发送邮件
        } catch (\Exception $e) {
            // 处理邮件发送失败的异常
            logger()->error('邮件发送失败: ' . $e->getMessage());
            return false;
        }
    }
}
