package com.ylx.massage.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.massage.domain.MaTechnician;
import com.ylx.massage.domain.dto.MaTechnicianMerchantQueryDTO;
import com.ylx.massage.domain.dto.MassageMerchantRecommendDto;
import com.ylx.massage.domain.vo.MaTechnicianMerchantDetailVO;
import com.ylx.massage.domain.vo.MaTechnicianMerchantListVO;
import com.ylx.massage.domain.vo.MassageProjectRecommendVo;
import com.ylx.massage.domain.vo.MerchantVo;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 技师Mapper接口
 *
 * @author ylx
 * @date 2024-03-22
 */
@Mapper
public interface MaTechnicianMapper extends BaseMapper<MaTechnician>
{
    /**
     * 查询技师
     *
     * @param id 技师主键
     * @return 技师
     */
    public MaTechnician selectMaTechnicianById(Long id);

    /**
     * 查询技师列表
     *
     * @param maTechnician 技师
     * @return 技师集合
     */
     List<MaTechnician> selectMaTechnicianList(MaTechnician maTechnician);

    /**
     * 新增技师
     *
     * @param maTechnician 技师
     * @return 结果
     */
    public int insertMaTechnician(MaTechnician maTechnician);

    /**
     * 修改技师
     *
     * @param maTechnician 技师
     * @return 结果
     */
    public int updateMaTechnician(MaTechnician maTechnician);

    /**
     * 删除技师
     *
     * @param id 技师主键
     * @return 结果
     */
    public int deleteMaTechnicianById(Long id);

    /**
     * 批量删除技师
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteMaTechnicianByIds(Long[] ids);
    /**
     * 后台查询商户列表
     *
     * @param page 分页参数
     * @param dto 查询条件
     * @return 商户分页列表
     */
    Page<MaTechnicianMerchantListVO> selectMerchantList(Page<MaTechnicianMerchantListVO> page,
                                                        @Param("dto") MaTechnicianMerchantQueryDTO dto);

    /**
     * 后台查询商户详情
     *
     * @param id 商户ID
     * @return 商户详情
     */
    MaTechnicianMerchantDetailVO selectMerchantDetailById(@Param("id") Long id);

    List<MerchantVo> getMerchantRecommend(@Param("dto") MassageMerchantRecommendDto dto);

    /**
     * 查询该城市是否有商户提供服务
     * @param areaCode
     * @return
     */
    @Select("SELECT EXISTS (" +
            "    SELECT 1" +
            "    FROM ma_technician t" +
            "    INNER JOIN ma_project p ON t.id = p.merchant_id" +
            "    WHERE t.te_area_code = #{areaCode}" +
            "      AND t.is_delete = 0" +
            "      AND t.audit_status = 2" +
            "      AND t.n_status2 = 0" +
            "      AND t.merchant_status = 0" +
            "      AND p.is_delete = 0" +
            "      AND p.audit_status = 1" +
            "      AND p.merchant_type = 0" +
            "      AND p.project_is_enable = 1   -- 根据实际业务调整：1启用，0禁用" +
            ") AS has_merchant_with_service")
    Boolean isHasMerchantCity(@Param("areaCode")  String areaCode);
}
