package com.xiang.xservice.application.script.xb.controller;

import com.google.common.collect.Lists;
import com.xiang.xservice.basic.common.resp.Result;
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
import com.xiang.xservice.application.script.xb.entity.request.xb.fund.QueryFundInfoReq;
import com.xiang.xservice.application.script.xb.entity.request.xb.fund.QueryFundListReq;
import com.xiang.xservice.application.script.xb.entity.request.xb.fund.QueryXbFundListReq;
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundInfo;
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
import com.xiang.xservice.application.script.xb.service.FundService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
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 java.util.List;
import java.util.Objects;

/**
 * @Author: xiang
 * @Date: 2025-05-14 16:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/xb")
public class XBController {

    private final FundService fundService;

    @PostMapping("/queryFundList")
    public Result<XbFundList> queryFundList(@RequestBody QueryXbFundListReq req) {
        List<XbFundList> result = fundService.queryFundList(req.getType());
        if (CollectionUtils.isEmpty(result)) {
            return Result.error("基金列表信息为空！");
        }
        return Result.success("success", result);
    }

    @PostMapping("/queryList")
    public Result<FundList> queryList(@RequestBody QueryFundListReq req) {
        List<FundList> result = fundService.queryTodayList(req.getDate(), req.getDataResources(), req.getDataSourceSwitch(), req.getCodeArr());
        if (CollectionUtils.isEmpty(result)) {
            return Result.error("基金列表信息为空！");
        }
        return Result.success("success", result);
    }

    @PostMapping("/queryFundInfo")
    public Result<FundInfo> queryFundInfo(@RequestBody QueryFundInfoReq req) {
        FundInfo fundInfo = fundService.queryFundInfo(req.getCode());
        if (Objects.nonNull(fundInfo)) {
            return Result.success("success", Lists.newArrayList(fundInfo));
        }
        return Result.error("查询基金信息为空！");
    }
}
