package top.continew.admin.business.service.Impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import top.continew.admin.business.mapper.TgUserMapper;
import top.continew.admin.business.model.entity.TgUser;
import top.continew.admin.business.model.query.TgUserQuery;
import top.continew.admin.business.model.req.TgUserReq;
import top.continew.admin.business.service.ITgUserService;
import top.continew.starter.extension.crud.model.resp.PageResp;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * tg用户 服务实现类
 * </p>
 *
 * @author xudm
 * @since 2024-12-14
 */
@Service
public class TgUserServiceImpl extends ServiceImpl<TgUserMapper, TgUser> implements ITgUserService {
    @Override
    public PageResp<TgUser> pageQuery(TgUserQuery queryVo) {
        Page<TgUser> page = new Page<>();
        page.setCurrent(queryVo.getPage() != 0 ? queryVo.getPage() : 1);
        page.setSize(queryVo.getSize() != 0 ? queryVo.getSize() : 10);

        List<TgUser> tgUserOfPage = getBaseMapper().getTgUserOfPage(queryVo, page);
        page.setRecords(tgUserOfPage);
        return PageResp.build(page, TgUser.class);
    }

    @Override
    public void disableTgUserByIds(List<Long> ids) {
        List<TgUser> tgUsers = listByIds(ids);
        tgUsers.forEach(u -> {
            u.setDisableFlag(1);
            u.setUpdatedTime(LocalDateTime.now());
        });
        getBaseMapper().updateById(tgUsers);
    }

    @Override
    public List<TgUser> getMyTeamUserListByType(Long id, String teamType) {
        return getBaseMapper().getMyTeamUserListByType(id, teamType);
    }

    @Override
    public void updateTgUserInfo(Long id, TgUserReq req) {
        TgUser byId = getById(id);
        BeanUtils.copyProperties(req, byId);
        byId.setUpdatedTime(LocalDateTime.now());
        getBaseMapper().updateById(byId);
    }
}
