package cn.stylefeng.team.portal.modular.management.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.portal.modular.management.entity.CommonAppLink;
import cn.stylefeng.team.portal.modular.management.pojo.request.CommonAppLinkRequest;
import cn.stylefeng.team.portal.modular.management.service.CommonAppLinkService;
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 CommonAppLinkController {

    @Resource
    private CommonAppLinkService commonAppLinkService;

    @PostResource(name = "添加通用应用链接", path = "/commonAppLink/add")
    public ResponseData<CommonAppLink> add(@RequestBody @Validated(CommonAppLinkRequest.add.class) CommonAppLinkRequest commonAppLinkRequest) {
        commonAppLinkService.add(commonAppLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除通用应用链接", path = "/commonAppLink/delete")
    public ResponseData<?> delete(@RequestBody @Validated(CommonAppLinkRequest.delete.class) CommonAppLinkRequest commonAppLinkRequest) {
        commonAppLinkService.del(commonAppLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除通用应用链接", path = "/commonAppLink/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) CommonAppLinkRequest commonAppLinkRequest) {
        commonAppLinkService.batchDelete(commonAppLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑通用应用链接", path = "/commonAppLink/edit")
    public ResponseData<?> edit(@RequestBody @Validated(CommonAppLinkRequest.edit.class) CommonAppLinkRequest commonAppLinkRequest) {
        commonAppLinkService.edit(commonAppLinkRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看通用应用链接详情", path = "/commonAppLink/detail")
    public ResponseData<CommonAppLink> detail(@Validated(CommonAppLinkRequest.detail.class) CommonAppLinkRequest commonAppLinkRequest) {
        return new SuccessResponseData<>(commonAppLinkService.detail(commonAppLinkRequest));
    }

    @GetResource(name = "获取通用应用链接列表（带分页）", path = "/commonAppLink/page")
    public ResponseData<PageResult<CommonAppLink>> page(CommonAppLinkRequest commonAppLinkRequest) {
        return new SuccessResponseData<>(commonAppLinkService.findPage(commonAppLinkRequest));
    }

}
