package cn.stylefeng.team.project.modular.filing.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.team.project.modular.filing.pojo.businesscount.BusinessCountRequest;
import cn.stylefeng.team.project.modular.filing.pojo.businesscount.BusinessCountResult;
import cn.stylefeng.team.project.modular.filing.pojo.page.BusinessDesignPageRequest;
import cn.stylefeng.team.project.modular.filing.pojo.page.BusinessDesignPageResultVo;
import cn.stylefeng.team.project.modular.filing.service.BusinessDesignService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ApiResource(name = "业务设计列表接口V2")
public class BusinessDesignController {

    @Resource
    private BusinessDesignService businessDesignService;

    @GetResource(name = "获取新的业务设计的列表", path = "/business/page/v2")
    public ResponseData<PageResult<BusinessDesignPageResultVo>> page(BusinessDesignPageRequest businessDesignPageRequest) {
        PageResult<BusinessDesignPageResultVo> result = businessDesignService.pageList(businessDesignPageRequest);
        return new SuccessResponseData<>(result);
    }

    @GetResource(name = "指定业务的数据统计", path = "/business/getBusinessStatCount")
    public ResponseData<BusinessCountResult> getBusinessStatCount(@Validated BusinessCountRequest businessCountRequest) {
        List<BusinessCountResult> businessStatInfo = businessDesignService.getBusinessStatInfo(
                CollectionUtil.set(false, businessCountRequest.getBusinessId()));

        if (businessStatInfo != null && !businessStatInfo.isEmpty()) {
            return new SuccessResponseData<>(businessStatInfo.get(0));
        }

        return new SuccessResponseData<>();
    }

}
