package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.annotation.rest.AnonymousGetMapping;
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto;
import cn.ysk.cashier.service.SummaryService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @author lyf
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/summary")
public class SummaryController {
    @Resource
    private SummaryService summaryService;

    @GetMapping
    private Object shopSummary(@RequestParam Integer shopId) {
        return summaryService.selectSummary(shopId);
    }

    @GetMapping("/date")
    private Object shopSummaryDate(@RequestParam Integer shopId, @RequestParam Integer day) {
        return summaryService.selectSummaryDate(shopId, day);
    }

    @GetMapping("/today")
    private Object shopSummaryDate(@RequestParam Integer shopId) {
        return summaryService.selectSummaryToday(shopId);
    }

    @GetMapping("/dateAmount")
    private Object shopSummaryAmount(@RequestParam Integer shopId, @RequestParam Integer day) {
        return summaryService.selectSummaryAmount(shopId, day);
    }


    @GetMapping("/dateProduct")
    private Object shopSummaryProduct(@RequestParam Integer shopId, @RequestParam Integer day,
                                      @RequestParam Integer page, @RequestParam Integer size) {
        return summaryService.selectSummaryProduct(shopId, day, page, size);
    }

    @GetMapping("/datePayType")
    private Object shopSummaryPayType(@RequestParam Integer shopId, @RequestParam Integer day) {
        return summaryService.selectSummaryPayType(shopId, day);
    }

    @GetMapping("/table")
    private Object shopSummaryTable(@RequestParam Integer shopId,
                                    @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                    @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        return summaryService.selectSummaryTable(shopId, startTime, endTime);
    }

    @PostMapping("/table/download")
    private void downloadShopSummaryTable(HttpServletResponse response, @RequestBody ShopTableSaleInfoDto exportRequest) throws IOException {
        summaryService.downloadTableSaleInfo(exportRequest, response);
    }

}
