package com.bonus.canteen.core.allocation.canteen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.allocation.canteen.model.AllocKind;
import com.bonus.canteen.core.allocation.canteen.vo.AllocKindVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AllocKindMapper extends BaseMapper<AllocKind> {
   Page<AllocKindVO> pageKind(@Param("page") Page<AllocKindVO> page, @Param("kindName") String kindName);

   @Select({"SELECT img_url, crtime, uptime FROM alloc_kind WHERE kind_name = #{kindName} ORDER BY id ASC LIMIT 1"})
   AllocKind getTimeByName(@Param("kindName") String kindName);

   @Select({"SELECT COUNT(*) FROM alloc_kind WHERE kind_name = #{kindName} AND stall_id IS NULL"})
   Long countForRepeatCheck(@Param("kindName") String kindName);

   @Select({"SELECT kind_name FROM alloc_kind GROUP BY kind_name"})
   List<AllocKind> listKindName();

   @Select({"SELECT kind_name, img_url FROM alloc_kind WHERE stall_id IS NULL"})
   List<AllocKind> listKindNameImg();

   List<AllocKind> listKindByNameList(@Param("kindNameList") List<String> kindNameList);

   @Select({"SELECT kind_name FROM alloc_kind WHERE stall_id = #{stallId}"})
   List<String> listStallKindName(@Param("stallId") Long stallId);
}
