package org.springblade.modules.martial.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.martial.mapper.MartialScheduleParticipantMapper;
import org.springblade.modules.martial.pojo.entity.MartialScheduleParticipant;
import org.springblade.modules.martial.service.IScheduleStatusService;
import org.springframework.stereotype.Service;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@RequiredArgsConstructor
public class ScheduleStatusServiceImpl implements IScheduleStatusService {

    private final MartialScheduleParticipantMapper scheduleParticipantMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
	public boolean updateParticipantCheckInStatus(Long participantId, String status) {
		if (participantId == null || status == null) {
			return false;
		}
		
		MartialScheduleParticipant participant = scheduleParticipantMapper.selectById(participantId);
		if (participant == null) {
			log.warn("参赛者不存在, participantId: {}", participantId);
			return false;
		}
		
		participant.setCheckInStatus(status);
		int result = scheduleParticipantMapper.updateById(participant);
		
		log.info("更新参赛者签到状态: participantId={}, status={}, result={}", participantId, status, result);
		return result > 0;
	}
}
