package cn.pluss.platform.user;

import cn.pluss.platform.entity.UserVoice;
import cn.pluss.platform.mapper.UserVoiceMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 用户播报配置表 服务类
 * </p>
 *
 * @author Djh
 * @since 2022-04-16
 */
public interface UserVoiceService extends IService<UserVoice> {

    /**
     * app获取播报配置
     * @return
     */
    UserVoice apiGetVoiceSetting();

    /**
     * app修改播报配置
     */
    void apiSetVoiceSetting(UserVoice userVoice);

    /**
     * 获取用户播报配置信息
     * @param userId
     * @return
     */
    default UserVoice getByUserId(Long userId) {
        LambdaQueryWrapper<UserVoice> qWrapper = Wrappers.lambdaQuery();
        qWrapper.eq(UserVoice::getUserId, userId);

        UserVoice userVoice = getBaseMapper().selectOne(qWrapper);

        if (userVoice == null) {
            return defValue(userId);
        } else {
            return userVoice;
        }
    }

    /**
     * 默认值
     * @param userId    用户id
     * @return
     */
    default UserVoice defValue(Long userId) {
        UserVoice userVoice = new UserVoice();
        userVoice.setUserId(userId);
        userVoice.setDeliveryOrder(UserVoice.ENABLE);
        userVoice.setMemberCharge(UserVoice.ENABLE);
        userVoice.setMemberConsume(UserVoice.ENABLE);
        userVoice.setPayCancel(UserVoice.ENABLE);
        userVoice.setPaySuccess(UserVoice.ENABLE);
        userVoice.setUrge(UserVoice.ENABLE);
        userVoice.setStoreOrder(UserVoice.ENABLE);

        return userVoice;
    }
}
