package com.backendsys.controller.Ai;

import com.backendsys.aspect.HttpRequestAspect;
import com.backendsys.entity.Ai.Aiivh.AiivhQuotaDTO;
import com.backendsys.entity.Ai.Aiivh.AiivhQuotaHistoryDTO;
import com.backendsys.entity.Ai.Aiivh.AiivhQuotaOrderDTO;
import com.backendsys.entity.PageDTO;
import com.backendsys.entity.System.SysResourcePointsDTO;
import com.backendsys.service.Ai.Aiivh.AiivhQuotaHistoryService;
import com.backendsys.service.Ai.Aiivh.AiivhQuotaOrderService;
import com.backendsys.service.Ai.Aiivh.AiivhQuotaService;
import com.backendsys.utils.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * AI数智人-配额
 */
@RestController
public class AiivhQuotaController {

    @Autowired
    private HttpRequestAspect httpRequestAspect;

    @Autowired
    private AiivhQuotaService aiivhQuotaService;

    @Autowired
    private AiivhQuotaOrderService aiivhQuotaOrderService;

    @Autowired
    private AiivhQuotaHistoryService aiivhQuotaHistoryService;

    /**
     * 积分兑换配额 (AI数字人形象)
     */
    @PreAuthorize("@sr.hasPermission('33')")
    @PostMapping("/api/ai/ivh/quota/pointToVirtualmanQuota")
    public Result pointToVirtualmanQuota(@Validated @RequestBody AiivhQuotaOrderDTO aiivhQuotaOrderDTO) {
        return Result.success(aiivhQuotaService.pointToVirtualmanQuota(aiivhQuotaOrderDTO));
    }

    /**
     * 获取配额积分 (AI数智人形象)
     */
    @PreAuthorize("@sr.hasPermission('33')")
    @GetMapping("/api/ai/ivh/quota/getResourceOfQuota")
    public Result getResourceOfQuoa(SysResourcePointsDTO sysResourcePointsDTO) {
        return Result.success(aiivhQuotaService.getResourceOfQuoa(sysResourcePointsDTO));
    }

    /**
     * 我的积分兑换记录
     */
    @PreAuthorize("@sr.hasPermission('33')")
    @GetMapping("/api/ai/ivh/quota/getMyQuotaOrder")
    public Result getMyQuotaOrder(@Validated PageDTO pageDTO, @Validated AiivhQuotaOrderDTO aiivhQuotaOrderDTO) {
        // [查询] 自身 UserId
        aiivhQuotaOrderDTO.setUser_id(httpRequestAspect.getUserId());
        return Result.success(aiivhQuotaOrderService.getQuotaOrderList(pageDTO.getPage_num(), pageDTO.getPage_size(), aiivhQuotaOrderDTO));
    }

    /**
     * 全部积分兑换记录
     */
    @PreAuthorize("@sr.hasPermission('33.1')")
    @GetMapping("/api/ai/ivh/quota/getQuotaOrder")
    public Result getQuotaOrder(@Validated PageDTO pageDTO, @Validated AiivhQuotaOrderDTO aiivhQuotaOrderDTO) {
        return Result.success(aiivhQuotaOrderService.getQuotaOrderList(pageDTO.getPage_num(), pageDTO.getPage_size(), aiivhQuotaOrderDTO));
    }

    /**
     * 我的配额操作记录
     */
    @PreAuthorize("@sr.hasPermission('33')")
    @GetMapping("/api/ai/ivh/quota/getMyQuotaHistory")
    public Result getMyQuotaHistory(@Validated PageDTO pageDTO, @Validated AiivhQuotaHistoryDTO aiivhQuotaHistoryDTO) {
        // [查询] 自身 UserId
        aiivhQuotaHistoryDTO.setUser_id(httpRequestAspect.getUserId());
        return Result.success(aiivhQuotaHistoryService.getQuotaHistoryList(pageDTO.getPage_num(), pageDTO.getPage_size(), aiivhQuotaHistoryDTO));
    }

    /**
     * 我的配额
     */
    @PreAuthorize("@sr.hasPermission('33')")
    @GetMapping("/api/ai/ivh/quota/getMyQuota")
    public Result getMyQuota(@Validated PageDTO pageDTO, @Validated AiivhQuotaDTO aiivhQuotaDTO) {
        // [查询] 自身 UserId
        aiivhQuotaDTO.setUser_id(httpRequestAspect.getUserId());
        return Result.success(aiivhQuotaService.getMyQuotaList(pageDTO.getPage_num(), pageDTO.getPage_size(), aiivhQuotaDTO));
    }

}
