package cn.iocoder.yudao.module.system.service.extra;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.extra.vo.AuthorizedAgentConfirmationPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.extra.ElderlyExtraAuthorizedAgentConfirmationDO;
import cn.iocoder.yudao.module.system.dal.mysql.extra.ElderlyExtraAuthorizedAgentConfirmationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.ELDERLY_EXTRA_AUTHORIZED_AGENT_CONFIRMATION_NOT_EXISTS;

@Service @Slf4j
public class ElderlyExtraAuthorizedAgentConfirmationServiceImpl implements ElderlyExtraAuthorizedAgentConfirmationService {
    @Resource private ElderlyExtraAuthorizedAgentConfirmationMapper mapper;

    @Override public Long create(ElderlyExtraAuthorizedAgentConfirmationDO createReqVO) { mapper.insert(createReqVO); return createReqVO.getId(); }
    @Override public void update(ElderlyExtraAuthorizedAgentConfirmationDO updateReqVO) { validateExists(updateReqVO.getId()); mapper.updateById(updateReqVO); }
    @Override public void delete(Long id) { validateExists(id); mapper.deleteById(id); }
    @Override public PageResult<ElderlyExtraAuthorizedAgentConfirmationDO> findPage(AuthorizedAgentConfirmationPageReqVO reqVO) { return mapper.selectPage(reqVO); }
    @Override public ElderlyExtraAuthorizedAgentConfirmationDO getDetail(Long id) { return validateExists(id); }
    @Override public List<ElderlyExtraAuthorizedAgentConfirmationDO> getListByElderId(Long elderId) { return mapper.selectList(new LambdaQueryWrapperX<ElderlyExtraAuthorizedAgentConfirmationDO>().eqIfPresent(ElderlyExtraAuthorizedAgentConfirmationDO::getElderId, elderId).orderByDesc(ElderlyExtraAuthorizedAgentConfirmationDO::getCreateTime)); }
    private ElderlyExtraAuthorizedAgentConfirmationDO validateExists(Long id) { ElderlyExtraAuthorizedAgentConfirmationDO r = mapper.selectById(id); if (r == null) throw exception(ELDERLY_EXTRA_AUTHORIZED_AGENT_CONFIRMATION_NOT_EXISTS); return r; }
}
