package cn.stylefeng.team.view.modular.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.view.api.entity.View;
import cn.stylefeng.team.view.modular.pojo.request.ViewRequest;
import cn.stylefeng.team.view.modular.service.ViewService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiResource(name = "业务视图")
public class DevOpsViewController {

    @Resource
    private ViewService viewService;

    @GetResource(name = "获取业务视图列表（带分页）", path = "/devopsView/page")
    public ResponseData<PageResult<View>> page(@Validated(BaseRequest.page.class) ViewRequest viewRequest) {
        return new SuccessResponseData<>(viewService.findPage(viewRequest));
    }

    @PostResource(name = "添加视图", path = "/devopsView/add")
    public ResponseData<View> add(@RequestBody @Validated(ViewRequest.add.class) ViewRequest viewRequest) {
        viewService.add(viewRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除视图", path = "/devopsView/delete")
    public ResponseData<?> delete(@RequestBody @Validated(ViewRequest.delete.class) ViewRequest viewRequest) {
        viewService.del(viewRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除视图", path = "/devopsView/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) ViewRequest viewRequest) {
        viewService.batchDelete(viewRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑视图", path = "/devopsView/edit")
    public ResponseData<?> edit(@RequestBody @Validated(ViewRequest.edit.class) ViewRequest viewRequest) {
        viewService.edit(viewRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看视图详情", path = "/devopsView/detail")
    public ResponseData<View> detail(@Validated(ViewRequest.detail.class) ViewRequest viewRequest) {
        return new SuccessResponseData<>(viewService.detail(viewRequest));
    }

}
