package com.petshop.backend.config;

import com.petshop.backend.service.AppointmentService;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component
public class ApplicationStartupListener implements ApplicationListener<ContextRefreshedEvent> {

    private final AppointmentService appointmentService;

    public ApplicationStartupListener(AppointmentService appointmentService) {
        this.appointmentService = appointmentService;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //update booked appointments to complete on startup
        appointmentService.updatePastAppointmentsStatus();
    }
}
