package link.at17.mid.tushare.api.common;

import java.util.List;
import java.util.Objects;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.yulichang.query.MPJLambdaQueryWrapper;

import link.at17.mid.tushare.data.models.StockInfo;
import link.at17.mid.tushare.data.service.StockInfoService;
import link.at17.mid.tushare.enums.ListStatus;
import link.at17.mid.tushare.enums.StockMarket;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/api/v1/common/stockInfo")
@Slf4j
public class StockInfoController {
	
	@Autowired
	StockInfoService stockInfoService;
	
	@GetMapping("list")
	private List<StockInfo> list(
	        @Param("listStatus") ListStatus listStatus,
	        @Param("stockMarket") StockMarket stockMarket) {
	    MPJLambdaQueryWrapper<StockInfo> ew = new MPJLambdaQueryWrapper<StockInfo>();
	    ew.setAlias("i");
        ew.eq(Objects.nonNull(listStatus), StockInfo::getListStatus, listStatus);
	    ew.likeLeft(Objects.nonNull(stockMarket), StockInfo::getTsCode, stockMarket);
		return stockInfoService.list(ew);
	}
}
