package com.ai.da.controller;

import com.ai.da.common.context.UserContext;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.Response;
import com.ai.da.mapper.primary.entity.CreditsDetail;
import com.ai.da.model.dto.QueryIncomeOrExpenditureDTO;
import com.ai.da.service.CreditsService;
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 javax.validation.Valid;

@CrossOrigin
@RestController
@RequestMapping("/api/credits")
@Api(tags = "积分")
@Slf4j
public class CreditsController {

    @Resource
    private CreditsService creditsService;

    @ApiOperation("获取当前积分")
    @GetMapping("/getCredits")
    public Response<String> getCredits() {
        String credits = creditsService.getCredits(UserContext.getUserHolder().getId());
        return Response.success(credits);
    }

    @ApiOperation("获取积分详细")
    @PostMapping("/getCreditsDetail")
    public Response<PageBaseResponse<CreditsDetail>> getCreditsDetail(@Valid @RequestBody QueryIncomeOrExpenditureDTO queryPageByTimeDTO) {
        PageBaseResponse<CreditsDetail> credits = creditsService.queryCreditsDetailsPage(queryPageByTimeDTO);
        return Response.success(credits);
    }


}
