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

import java.time.LocalDateTime;
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 link.at17.mid.tushare.data.service.StockCalendarService;
import link.at17.mid.tushare.enums.StockMarket;
import link.at17.mid.tushare.system.util.LocalDateTimeUtils;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/api/v1/common/calendar")
@Slf4j
public class StockCalendarController {
	
	@Autowired
	StockCalendarService stockCalendarService;
	
	@GetMapping("todayIsOpen")
	private String todayIsOpen(@Param("stockMarket") StockMarket stockMarket) {
		return String.valueOf(stockCalendarService.isOpen(LocalDateTime.now(), stockMarket));
	}
	
	@GetMapping("isOpen")
	private String isOpen(@Param("stockMarket") StockMarket stockMarket, @Param("date") String date) {
	    LocalDateTime dateTime = LocalDateTimeUtils.parseDate(date);
	    
	    return String.valueOf(stockCalendarService.isOpen(dateTime, stockMarket));
	}

}
