package com.aegis.emergency.plan.service.impl;

import com.aegis.emergency.plan.domain.PlanUsage;
import com.aegis.emergency.plan.mapper.PlanUsageMapper;
import com.aegis.emergency.plan.service.IPlanUsageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 预案使用记录 Service 实现
 */
@Service
public class PlanUsageServiceImpl extends ServiceImpl<PlanUsageMapper, PlanUsage> implements IPlanUsageService {

    @Override
    public PlanUsage recordUsage(PlanUsage usage) {
        Objects.requireNonNull(usage, "usage must not be null");
        Objects.requireNonNull(usage.getPlanId(), "planId must not be null");
        this.save(usage);
        return usage;
    }

    @Override
    public List<PlanUsage> listByPlanId(Long planId) {
        if (planId == null) {
            return Collections.emptyList();
        }
        return this.lambdaQuery()
            .eq(PlanUsage::getPlanId, planId)
            .list();
    }

    @Override
    public boolean removeByPlanId(Long planId) {
        if (planId == null) {
            return false;
        }
        return this.lambdaUpdate()
            .eq(PlanUsage::getPlanId, planId)
            .remove();
    }
}