package com.xindazhou.framework.social.dal.mysql;

import com.xindazhou.framework.common.pojo.PageResult;
import com.xindazhou.framework.common.pojo.PageParam;
import com.xindazhou.framework.mybatis.core.mapper.BaseMapperX;
import com.xindazhou.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.xindazhou.framework.social.dal.dataobject.SocialUserDO;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDateTime;

@Mapper
public interface SocialUserMapper extends BaseMapperX<SocialUserDO> {

    default SocialUserDO selectByTypeAndCodeAnState(Integer type, String code, String state) {
        return selectOne(SocialUserDO::getType, type,
                SocialUserDO::getCode, code,
                SocialUserDO::getState, state);
    }

    default SocialUserDO selectByTypeAndOpenid(Integer type, String openid) {
        return selectFirstOne(SocialUserDO::getType, type,
                SocialUserDO::getOpenid, openid);
    }

    default PageResult<SocialUserDO> selectPage(PageParam pageParam, Integer type, String nickname, String openid, LocalDateTime[] createTime) {
        return selectPage(pageParam, new LambdaQueryWrapperX<SocialUserDO>()
                .eqIfPresent(SocialUserDO::getType, type)
                .likeIfPresent(SocialUserDO::getNickname, nickname)
                .likeIfPresent(SocialUserDO::getOpenid, openid)
                .betweenIfPresent(SocialUserDO::getCreateTime, createTime)
                .orderByDesc(SocialUserDO::getId));
    }

}
