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

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
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.entity.Business;
import cn.stylefeng.team.project.modular.business.pojo.request.BusinessRequest;
import cn.stylefeng.team.project.modular.business.pojo.response.BusinessVo;
import cn.stylefeng.team.project.modular.business.service.BusinessService;
import cn.stylefeng.team.project.modular.businessrender.pojo.response.BusinessModelFormViewResponse;
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.List;

@RestController
@ApiResource(name = "业务")
public class BusinessController {

    @Resource
    private BusinessService businessService;

    @PostResource(name = "添加业务", path = "/business/add")
    public ResponseData<Business> add(@RequestBody @Validated(BusinessRequest.add.class) BusinessRequest businessRequest) {
        businessService.add(businessRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除业务", path = "/business/delete")
    public ResponseData<?> delete(@RequestBody @Validated(BusinessRequest.delete.class) BusinessRequest businessRequest) {
        businessService.del(businessRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除业务", path = "/business/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) BusinessRequest businessRequest) {
        businessService.batchDelete(businessRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑业务", path = "/business/edit")
    public ResponseData<?> edit(@RequestBody @Validated(BusinessRequest.edit.class) BusinessRequest businessRequest) {
        businessService.edit(businessRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看业务详情", path = "/business/detail")
    public ResponseData<Business> detail(@Validated(BusinessRequest.detail.class) BusinessRequest businessRequest) {
        return new SuccessResponseData<>(businessService.detail(businessRequest));
    }

    @GetResource(name = "获取业务列表", path = "/business/list")
    public ResponseData<List<Business>> list(BusinessRequest businessRequest) {
        return new SuccessResponseData<>(businessService.findList(businessRequest));
    }

    @GetResource(name = "获取业务列表（带分页）", path = "/business/page")
    public ResponseData<PageResult<BusinessVo>> page(BusinessRequest businessRequest) {
        return new SuccessResponseData<>(businessService.findPage(businessRequest));
    }

    @GetResource(name = "获取指定业务下所有的模型，表单，视图", path = "/business/getBusinessModelFormView")
    public ResponseData<BusinessModelFormViewResponse> getBusinessModelFormView(@Validated(BaseRequest.detail.class) BusinessRequest businessRequest) {
        BusinessModelFormViewResponse businessModelFormViewResponse = businessService.getBusinessModelFormView(businessRequest);
        return new SuccessResponseData<>(businessModelFormViewResponse);
    }

}
