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

import com.bonus.canteen.core.allocation.api.AllocMealtimeApi;
import com.bonus.canteen.core.allocation.canteen.dto.ModifyMealtimeUseDTO;
import com.bonus.canteen.core.allocation.canteen.param.AllocCanteenStallParam;
import com.bonus.canteen.core.menu.model.AllocMealtimeModel;
import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.common.houqin.encrypt.RequiresGuest;
import com.bonus.canteen.core.allocation.canteen.param.AllocCanteenStallParam;
import com.bonus.canteen.core.menu.model.AllocMealtimeModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping({"/api/v2/alloc/mealtime"})
@Api(
   tags = {"lsh_餐次时段控制器"}
)
public class AllocMealtimeController {
   private static final Logger log = LoggerFactory.getLogger(AllocMealtimeController.class);
   @Resource
   @Lazy
   private AllocMealtimeApi allocMealtimeApi;

   @ApiOperation("查询餐次时段列表")
   @PostMapping({"/list-by-param"})
   @RequiresGuest
   public List<AllocMealtimeModel> listByParam(@RequestBody AllocCanteenStallParam request) {
      return this.allocMealtimeApi.listMealtime(request.getCanteenId(), request.getStallId());
   }

   @ApiOperation("查询启用的餐次时段列表")
   @PostMapping({"/list-use-by-param"})
   @RequiresGuest
   public List<AllocMealtimeModel> listUseByParam(@RequestBody AllocCanteenStallParam param) {
      return this.allocMealtimeApi.listUseAvailableMealtime(param.getCanteenId(), param.getStallId(), LeConstants.COMMON_YES);
   }

   @ApiOperation("新增食堂时，查询商户餐次列表")
   @PostMapping({"/list-for-canteen"})
   public List<AllocMealtimeModel> listForCanteen() {
      return this.allocMealtimeApi.listMealtime(null,null);
   }

   @ApiOperation("新增档口时，查询食堂餐次列表")
   @PostMapping({"/list-for-stall"})
   public List<AllocMealtimeModel> listForStall(@RequestBody Long dto) {
      return this.allocMealtimeApi.listMealtime(dto, null);
   }

   @ApiOperation("根据食堂id或档口id，查询餐次列表")
   @PostMapping({"/list-applet"})
   public List<AllocMealtimeModel> listApplet(@RequestBody AllocCanteenStallParam param) {
      return this.allocMealtimeApi.listUseMealtimeForApplet(param.getCanteenId(), param.getStallId(), param.getQueryDate());
   }

   @ApiOperation("修改餐次 启用状态")
   @PostMapping({"/modify-mealtime-use"})
   public void modifyMealtimeUse(@RequestBody @Valid ModifyMealtimeUseDTO param) {
      this.allocMealtimeApi.modifyMealtimeUse(param);
   }
}
