package com.yn.bftl.thirdparty.common.repository;

import com.yn.bftl.common.modules.subaccount.entity.Statement;
import com.yn.bftl.common.modules.subaccount.enums.StatementType;
import com.yn.bftl.common.modules.subaccount.enums.SubaccountType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 结算单Repository
 *
 * @author chendehuihuo
 * @date 2021/11/22
 **/
@Repository
public interface StatementRepository extends JpaRepository<Statement, Long> {

    Statement findFirstByShippingId(Long shippingId);

    /**
     * 结算单-查询
     *
     * @param shippingId     发货单ID
     * @param subaccountType 分账类型
     * @param statementType  结算单类型
     * @return 结算单
     * @description
     */
    Statement findByShippingIdAndSubaccountTypeAndStatementType(Long shippingId, SubaccountType subaccountType, StatementType statementType);

    Statement findFirstByAfterSaleId(Long afterSaleId);

    List<Statement> findAllByShippingId(Long ShippingId);

    /**
     * 结算单-根据发货单ID和结算类型查询
     *
     * @param ShippingId    发货单ID
     * @param statementType 结算类型
     * @return 结算单列表
     * @author huabiao
     * @create 2023/2/11  16:36
     */
    List<Statement> findAllByShippingIdAndStatementType(Long ShippingId, StatementType statementType);

    /**
     * 结算单-根据订单查询
     *
     * @param orderId:订单ID
     * @param statementType:服务单服务费类型
     * @return 结算单列表
     * @author huabiao
     * @create 2022/9/3  15:38
     */
    List<Statement> findAllByOrdersIdAndStatementType(Long orderId, StatementType statementType);

    /**
     * 结算单-判断是否存在
     *
     * @param orderId       订单ID
     * @param statementType 结算单类型
     * @return true:存在、false:不存在
     * @author huabiao
     * @create 2022/9/2  14:54
     */
    Boolean existsByOrdersIdAndStatementType(Long orderId, StatementType statementType);

    /**
     * 结算单-判断是否存在
     *
     * @param afterSaleId:售后单ID
     * @return true:存在、false:不存在
     * @author huabiao
     * @create 2022/9/2  14:54
     */
    Boolean existsByAfterSaleId(Long afterSaleId);

    /**
     * 结算单-根据订单查询
     *
     * @param orderId:订单ID
     * @return 结算单列表
     * @author huabiao
     * @create 2022/12/21  15:38
     */
    List<Statement> findAllByOrdersId(Long orderId);

    /**
     * 结算单-根据发货单ID和分账类型查询
     *
     * @param shippingId     发货单ID
     * @param subaccountType 分账类型
     * @return 结算单列表
     * @author huabiao
     * @create 2023/4/5  21:50
     */
    List<Statement> findAllByShippingIdAndSubaccountType(Long shippingId, SubaccountType subaccountType);

    /**
     * 结算单-根据发货单ID和分账类型查询
     *
     * @param orderId        订单ID
     * @param subaccountType 分账类型
     * @return 结算单列表
     * @author huabiao
     * @create 2023/4/5  21:50
     */
    List<Statement> findAllByOrdersIdAndSubaccountType(Long orderId, SubaccountType subaccountType);
}
