package cn.stylefeng.team.project.modular.businessrender.contoller;

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.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.team.project.api.pojo.BusinessRenderDetailVo;
import cn.stylefeng.team.project.api.pojo.BusinessSearchRequest;
import cn.stylefeng.team.project.api.pojo.request.BusinessSaveRequest;
import cn.stylefeng.team.project.api.pojo.request.BusinessUpdateRequest;
import cn.stylefeng.team.project.modular.business.pojo.request.BusinessDeleteBatchRequest;
import cn.stylefeng.team.project.modular.business.pojo.request.BusinessDeleteRequest;
import cn.stylefeng.team.project.modular.businessrender.pojo.request.BusinessRenderDetailRequest;
import cn.stylefeng.team.project.modular.businessrender.service.BusinessRenderService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@ApiResource(name = "业务渲染控制器", requiredPermission = true, requirePermissionCode = "APP_DESIGN_PREVIEW")
public class BusinessRenderController {

    @Resource
    private BusinessRenderService businessRenderService;

    @PostResource(name = "渲染业务列表数据", path = "/businessRender/getListData")
    public ResponseData<PageResult<Map<String, Object>>> getListData(@RequestBody @Validated BusinessSearchRequest businessSearchRequest) {
        PageResult<Map<String, Object>> viewPageData = businessRenderService.getViewPageData(businessSearchRequest);
        return new SuccessResponseData<>(viewPageData);
    }

    @GetResource(name = "获取数据的详情", path = "/businessRender/getDetail")
    public ResponseData<BusinessRenderDetailVo> getDetail(@Validated BusinessRenderDetailRequest businessRenderDetailRequest) {
        BusinessRenderDetailVo detail = businessRenderService.getDetail(businessRenderDetailRequest);
        return new SuccessResponseData<>(detail);
    }

    @PostResource(name = "保存数据", path = "/businessRender/save")
    public ResponseData<?> save(@RequestBody @Validated BusinessSaveRequest businessSaveRequest) {
        businessRenderService.save(businessSaveRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "更新数据", path = "/businessRender/update")
    public ResponseData<?> update(@RequestBody @Validated BusinessUpdateRequest businessUpdateRequest) {
        businessRenderService.update(businessUpdateRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除单个记录", path = "/businessRender/delete")
    public ResponseData<?> delete(@RequestBody @Validated BusinessDeleteRequest businessDeleteRequest) {
        businessRenderService.deleteBusiness(businessDeleteRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除数据", path = "/businessRender/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated BusinessDeleteBatchRequest businessDeleteBatchRequest) {
        businessRenderService.deleteBusinessBatch(businessDeleteBatchRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "导出数据到Excel", path = "/businessRender/exportData")
    public void exportData(@Validated BusinessSearchRequest businessSearchRequest) {
        businessRenderService.exportData(businessSearchRequest);
    }

}
