package com.yolo.keyboard.dal.mysql.tenantcommission;

import com.yolo.keyboard.controller.admin.tenantcommission.vo.KeyboardTenantCommissionPageReqVO;
import com.yolo.keyboard.dal.dataobject.tenantcommission.KeyboardTenantCommissionDO;
import com.yolo.keyboard.framework.common.pojo.PageResult;
import com.yolo.keyboard.framework.mybatis.core.mapper.BaseMapperX;
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 租户分成记录 Mapper
 *
 * @author ziin
 */
@Mapper
public interface KeyboardTenantCommissionMapper extends BaseMapperX<KeyboardTenantCommissionDO> {

    /**
     * 根据交易ID查询分成记录
     */
    default KeyboardTenantCommissionDO selectByTransactionId(String transactionId) {
        return selectOne(KeyboardTenantCommissionDO::getTransactionId, transactionId);
    }

    /**
     * 根据内购记录ID查询分成记录
     */
    default KeyboardTenantCommissionDO selectByPurchaseRecordId(Integer purchaseRecordId) {
        return selectOne(KeyboardTenantCommissionDO::getPurchaseRecordId, purchaseRecordId);
    }

    default PageResult<KeyboardTenantCommissionDO> selectPage(KeyboardTenantCommissionPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardTenantCommissionDO>()
                .eqIfPresent(KeyboardTenantCommissionDO::getPurchaseRecordId, reqVO.getPurchaseRecordId())
                .eqIfPresent(KeyboardTenantCommissionDO::getTransactionId, reqVO.getTransactionId())
                .eqIfPresent(KeyboardTenantCommissionDO::getInviteeUserId, reqVO.getInviteeUserId())
                .eqIfPresent(KeyboardTenantCommissionDO::getInviterUserId, reqVO.getInviterUserId())
                .eqIfPresent(KeyboardTenantCommissionDO::getPurchaseAmount, reqVO.getPurchaseAmount())
                .eqIfPresent(KeyboardTenantCommissionDO::getCommissionRate, reqVO.getCommissionRate())
                .eqIfPresent(KeyboardTenantCommissionDO::getCommissionAmount, reqVO.getCommissionAmount())
                .eqIfPresent(KeyboardTenantCommissionDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(KeyboardTenantCommissionDO::getPurchaseTime, reqVO.getPurchaseTime())
                .eqIfPresent(KeyboardTenantCommissionDO::getSettledAt, reqVO.getSettledAt())
                .eqIfPresent(KeyboardTenantCommissionDO::getBalanceTransactionId, reqVO.getBalanceTransactionId())
                .eqIfPresent(KeyboardTenantCommissionDO::getCreatedAt, reqVO.getCreatedAt())
                .eqIfPresent(KeyboardTenantCommissionDO::getUpdatedAt, reqVO.getUpdatedAt())
                .eqIfPresent(KeyboardTenantCommissionDO::getRemark, reqVO.getRemark())
                .orderByDesc(KeyboardTenantCommissionDO::getId));
    }

}
