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

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.MpActivityQueryReq;
import com.seer.teach.mp.admin.controller.req.MpActivityReq;
import com.seer.teach.mp.admin.controller.resp.AdminActivityResp;
import com.seer.teach.mp.admin.service.IAdminActivityService;
import com.seer.teach.mp.admin.convert.AdminActivityConvert;
import com.seer.teach.mp.entity.MpActivityEntity;
import com.seer.teach.mp.service.IMpActivityService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 管理端代理商活动服务实现类
 * </p>
 *
 * @author Lingma
 * @since 2025-12-30
 */
@Service
@RequiredArgsConstructor
public class AdminActivityServiceImpl implements IAdminActivityService {

    private final IMpActivityService agentActivityService;

    @Override
    public PageListBean<AdminActivityResp> pageList(MpActivityQueryReq query) {
        Page<MpActivityEntity> page = new Page<>(query.getPageNo(), query.getPageSize());
        var pageResult = agentActivityService.page(page, new LambdaQueryWrapper<>(MpActivityEntity.class)
                .like(StringUtils.isNotBlank(query.getActivityName()), MpActivityEntity::getActivityName, query.getActivityName())
                .eq(Objects.nonNull(query.getStatus()), MpActivityEntity::getStatus, query.getStatus()));
        return PageConverterUtils.convertPageListBean(pageResult, AdminActivityConvert.INSTANCE::convertToRespList);
    }

    @Override
    public boolean saveOrUpdateActivity(MpActivityReq request) {
        MpActivityEntity entity = AdminActivityConvert.INSTANCE.convert(request);
        return agentActivityService.saveOrUpdateActivity(entity);
    }

    @Override
    public boolean deleteActivity(Integer id) {
        return agentActivityService.deleteActivity(id);
    }

    @Override
    public AdminActivityResp getById(Integer id) {
        MpActivityEntity entity = agentActivityService.getById(id);
        return AdminActivityConvert.INSTANCE.convertToResp(entity);
    }
}