package com.seer.teach.mp.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.utils.PageConverterUtils;
import com.seer.teach.mp.admin.controller.req.ActivityInfoCollectionQueryReq;
import com.seer.teach.mp.admin.controller.resp.AdminActivityInfoCollectionResp;
import com.seer.teach.mp.admin.convert.AdminActivityInfoCollectionConvert;
import com.seer.teach.mp.entity.MpActivityInfoCollectionEntity;
import com.seer.teach.mp.service.IMpActivityInfoCollectionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Service
@Slf4j
@RequiredArgsConstructor
public class AdminActivityInfoCollectionService {

    private final IMpActivityInfoCollectionService mpActivityInfoCollectionService;

    /**
     * 分页查询活动信息收集记录
     *
     * @param req 查询参数
     * @return 分页结果
     */
    public PageListBean<AdminActivityInfoCollectionResp> pageList(ActivityInfoCollectionQueryReq req) {
        Page<MpActivityInfoCollectionEntity> page = new Page<>(req.getPageNo(), req.getPageSize());
        LambdaQueryWrapper<MpActivityInfoCollectionEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Objects.nonNull(req.getChildName()) && !req.getChildName().isEmpty(), MpActivityInfoCollectionEntity::getChildName, req.getChildName())
                .like(Objects.nonNull(req.getGrade()) && !req.getGrade().isEmpty(), MpActivityInfoCollectionEntity::getGrade, req.getGrade())
                .like(Objects.nonNull(req.getSchool()) && !req.getSchool().isEmpty(), MpActivityInfoCollectionEntity::getSchool, req.getSchool())
                .like(Objects.nonNull(req.getChildGender()) && !req.getChildGender().isEmpty(), MpActivityInfoCollectionEntity::getChildGender, req.getChildGender())
                .orderByDesc(MpActivityInfoCollectionEntity::getCreateTime);
        Page<MpActivityInfoCollectionEntity> result = mpActivityInfoCollectionService.page(page, wrapper);
        return PageConverterUtils.convertPageListBean(result, AdminActivityInfoCollectionConvert.INSTANCE::convertToRespList);
    }

    /**
     * 获取活动信息收集记录详情
     * @param id 记录ID
     * @return 详情
     */
    public AdminActivityInfoCollectionResp getDetail(Integer id) {
        MpActivityInfoCollectionEntity entity = mpActivityInfoCollectionService.getById(id);
        return AdminActivityInfoCollectionConvert.INSTANCE.convertToResp(entity);
    }

    /**
     * 删除活动信息收集记录
     * @param ids 删除的ID列表
     * @return 删除结果
     */
    public boolean delete(List<Integer> ids) {
        return mpActivityInfoCollectionService.removeByIds(ids);
    }
}
