package cn.novalon.gym.manage.groupcourse.event;

import cn.novalon.gym.manage.groupcourse.event.BookingReminderEvent.ReminderType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

/**
 * 预约提醒事件发布器
 * 
 * 使用Spring事件机制发布预约相关事件
 * 
 * @author 张翔
 * @date 2026-06-01
 */
@Component
public class BookingReminderEventPublisher {

    private static final Logger logger = LoggerFactory.getLogger(BookingReminderEventPublisher.class);

    private final ApplicationEventPublisher eventPublisher;

    public BookingReminderEventPublisher(ApplicationEventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher;
    }

    /**
     * 发布预约成功事件
     * 
     * @param bookingId 预约ID
     * @param memberId 会员ID
     * @param courseName 课程名称
     * @param courseTime 课程时间
     */
    public void publishBookingSuccessEvent(Long bookingId, Long memberId, String courseName, String courseTime) {
        BookingReminderEvent event = new BookingReminderEvent(
                this, bookingId, memberId, courseName, courseTime, ReminderType.BOOKING_SUCCESS);
        
        logger.info("发布预约成功事件：bookingId={}, memberId={}", bookingId, memberId);
        eventPublisher.publishEvent(event);
    }

    /**
     * 发布课程即将开始提醒事件
     * 
     * @param bookingId 预约ID
     * @param memberId 会员ID
     * @param courseName 课程名称
     * @param courseTime 课程时间
     */
    public void publishCourseReminderEvent(Long bookingId, Long memberId, String courseName, String courseTime) {
        BookingReminderEvent event = new BookingReminderEvent(
                this, bookingId, memberId, courseName, courseTime, ReminderType.COURSE_REMINDER);
        
        logger.info("发布课程提醒事件：bookingId={}, memberId={}", bookingId, memberId);
        eventPublisher.publishEvent(event);
    }

    /**
     * 发布预约取消事件
     * 
     * @param bookingId 预约ID
     * @param memberId 会员ID
     * @param courseName 课程名称
     */
    public void publishBookingCancelEvent(Long bookingId, Long memberId, String courseName) {
        BookingReminderEvent event = new BookingReminderEvent(
                this, bookingId, memberId, courseName, null, ReminderType.BOOKING_CANCEL);
        
        logger.info("发布预约取消事件：bookingId={}, memberId={}", bookingId, memberId);
        eventPublisher.publishEvent(event);
    }
}