package com.aegis.notification.service.channel;

import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.aegis.notification.domain.Notification;
import com.aegis.notification.mapper.NotificationMapper;

/**
 * 短信渠道（预留实现）
 * 
 * @author aegis
 */
@Service
public class SmsChannel implements INotificationChannel {
    
    private static final Logger log = LoggerFactory.getLogger(SmsChannel.class);
    
    @Autowired
    private NotificationMapper notificationMapper;
    
    @Override
    public boolean send(Notification notification) {
        try {
            // TODO: 对接短信网关（如阿里云短信、腾讯云短信等）
            // 1. 获取接收者手机号（从用户信息中获取）
            // 2. 调用短信网关API发送
            // 3. 记录发送结果
            
            // 暂时模拟发送成功
            notification.setStatus("sent");
            notification.setSendTime(new Date());
            notificationMapper.updateNotification(notification);
            
            log.info("短信通知发送成功：通知ID={}, 接收者={}", notification.getId(), notification.getReceiverId());
            return true;
        } catch (Exception e) {
            log.error("短信通知发送失败：通知ID={}, 错误={}", notification.getId(), e.getMessage(), e);
            notification.setStatus("failed");
            notification.setRemark("发送失败：" + e.getMessage());
            notificationMapper.updateNotification(notification);
            return false;
        }
    }
    
    @Override
    public String getChannelName() {
        return "sms";
    }
    
    @Override
    public boolean supports(String channel) {
        return "sms".equals(channel);
    }
}