package com.ai.da.controller;


import com.ai.da.common.context.UserContext;
import com.ai.da.common.response.Response;
import com.ai.da.mapper.primary.DesignMapper;
import com.ai.da.mapper.primary.TrialOrderMapper;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.model.dto.UserDesignStatisticDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

@Api(tags = "便利查询")
@Slf4j
@RestController
@RequestMapping("/api/inquiry")
public class ConvenientInquiryController {

    @Resource
    private TrialOrderMapper trialOrderMapper;

    @Resource
    private DesignMapper designMapper;

    @ApiOperation("获取当前所有试用用户")
    @GetMapping("/getTrial")
    public Response<List<TrialOrder>> getTrial(){
        Long accountId = UserContext.getUserHolder().getId();
        if (accountId.equals(31L) || accountId.equals(87L) || accountId.equals(83L)){
            List<TrialOrder> trialOrders = trialOrderMapper.selectList(null);
            return Response.success(trialOrders);
        }else {
            return Response.fail("Sorry, you don't have permission");
        }
    }

    @ApiOperation("获取指定时间区间内所有用户design的使用情况")
    @GetMapping("/getDesignStatistic")
    public Response<List<UserDesignStatisticDTO>> getDesignStatistic(@RequestParam String startTime,@RequestParam String endTime){
        Long accountId = UserContext.getUserHolder().getId();
        if (accountId.equals(31L) || accountId.equals(87L) || accountId.equals(83L)){
            List<UserDesignStatisticDTO> designStatistic = designMapper.getDesignStatistic(startTime, endTime);
            return Response.success(designStatistic);
        }else {
            return Response.fail("Sorry, you don't have permission");
        }
    }

}
