/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package cn.ysk.cashier.repository;

import cn.ysk.cashier.pojo.TbShopPayType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
* @website https://eladmin.vip
* @author lyf
* @date 2023-11-03
**/
public interface TbShopPayTypeRepository extends JpaRepository<TbShopPayType, Integer>, JpaSpecificationExecutor<TbShopPayType> {
    @Modifying
    @Query(value = "INSERT INTO `tb_shop_pay_type` ( shop_id, `pay_type`, `pay_name`, `is_show_shortcut`, `is_refundable`, `is_open_cash_drawer`, `is_system`, `is_ideal`, `is_display`, `icon` )\n" +
            "VALUES\n" +
            "\t( :shopId, 'cash', '现金', 1, 0, 1, 0, 1, 1, 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240302/2dab947729d640fba7709b7c0b42bfef.png' ),(\n" +
            "\t\t:shopId,\n" +
            "\t\t'bank',\n" +
            "\t\t'银行卡',\n" +
            "\t\t1,\n" +
            "\t\t0,\n" +
            "\t\t1,\n" +
            "\t\t0,\n" +
            "\t\t1,\n" +
            "\t\t1,\n" +
            "\t\t'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240302/14b20cf721304b7fa2f01e6e75fab403.png' \n" +
            "\t\t),(:shopId,\n" +
            "\t\t'scanCode',\n" +
            "\t\t'扫码支付',\n" +
            "\t\t1,\n" +
            "\t\t0,\n" +
            "\t\t1,\n" +
            "\t\t0,\n" +
            "\t\t1,\n" +
            "\t\t1,\n" +
            "\t\t'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240302/9ff08224680446c8b3978844da99bbaa.png' \n" +
            "\t\t),(:shopId,\n" +
            "\t\t'deposit',\n" +
            "\t\t'储值卡',\n" +
            "\t\t1,\n" +
            "\t\t0,\n" +
            "\t\t1,\n" +
            "\t\t0,\n" +
            "\t\t1,\n" +
            "\t\t1,\n" +
            "\t'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240302/18d40f471a924d55b4eb13e5f553734d.png' \n" +
            "\t)",nativeQuery = true)
    Integer creatPayType(@Param("shopId") String shopId);

    @Query("select t from TbShopPayType t where t.payType=:payType and t.shopId=:shopId")
    TbShopPayType findByPayType(@Param("payType")String payType,@Param("shopId") String shopId);

    @Query("select t from TbShopPayType t where t.shopId=:s")
    List<TbShopPayType> findByShopId(String s);
}
