<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.m2pool.lease.mapper.LeaseShopConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.m2pool.lease.entity.LeaseShopConfig">
        <id column="id" property="id" />
        <result column="shop_id" property="shopId" />
        <result column="product_id" property="productId" />
        <result column="pay_coin" property="payCoin" />
        <result column="pay_type" property="payType" />
        <result column="pay_address" property="payAddress" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="del" property="del" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, shop_id, product_id, pay_coin, pay_type, pay_address, create_time, update_time, del
    </sql>
    <select id="getChainAndList" resultType="com.m2pool.lease.dto.CoinFullDto">
        SELECT chain as chainValue,chain as chainLabel,coin as `coinValue`,coin_full as coinLabel FROM lease_chain_coin_config
        <where>
            <if test="chain != null">
                 chain = #{chain}
            </if>
        </where>
    </select>
    <select id="getChainAndListForSeller" resultType="com.m2pool.lease.dto.CoinFullDto">
        select uwd.pay_coin as coinValue,ccc.coin_full as coinLabel,uwd.chain as chainLabel,uwd.chain as chainValue
        from lease_chain_coin_config  ccc
        JOIN lease_shop_config uwd on ccc.coin = uwd.pay_coin and ccc.`chain` = uwd.chain
        where uwd.shop_id = #{shopId} and del = 0
    </select>
    <select id="getCoinIconByChainAndCoin" resultType="com.m2pool.lease.entity.LeaseShopConfig">
        select coin_image as payCoinImage,coin as payCoin,chain   from lease_chain_coin_config where `chain` = #{chain}
        AND (
        <foreach collection="coinList" item="item" separator="OR">
            coin = #{item}
        </foreach>
        )
    </select>
    <select id="selectShopConfigByShopIdAndSymbolAndChain" resultType="com.m2pool.lease.dto.ShopConfigDelDto">
        select shop_id as shopId,pay_address as payAddress,chain,del
        from lease_shop_config
        where
            del = 0 and
        (
        <foreach collection="list" item="item" separator="OR">
            (`shop_id` = #{item.shopId} AND chain = #{item.chain} AND pay_coin = #{item.coin})
        </foreach>
        )
    </select>
    <select id="getPayType" resultType="com.m2pool.lease.dto.PayTypeDto">
        select chain,pay_coin as coin,pay_coin_image as image,shop_id as shopId
        from lease_shop_config
        where del = false AND shop_id IN
        <foreach item="item" collection="list" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>
    <select id="getShopWalletInfoList" resultType="com.m2pool.lease.dto.v2.ShopWalletInfoDto">
        SELECT
            id,
            shop_id as shopId,
            pay_address as payAddress,
            chain,
            pay_coin as payCoin,
            pay_coin_image as image,
            balance
        FROM
            lease_shop_config
        WHERE
            shop_id = #{shopId} AND del = 0
    </select>
    <select id="getShopWalletInfo" resultType="com.m2pool.lease.dto.v2.ShopWalletInfoDto">
        SELECT
            id,
            shop_id as shopId,
            pay_address as payAddress,
            chain,
            pay_coin as payCoin,
            pay_coin_image as image,
            balance
        FROM
            lease_shop_config
        WHERE
            shop_id = #{shopId} AND pay_address = #{address} AND pay_coin = #{coin} AND chain = #{chain} AND del = 0
    </select>


</mapper>
