package com.zcloud.domain.web;


import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.domain.api.DomainGroupServiceI;
import com.zcloud.domain.dto.DomainGroupAddCmd;
import com.zcloud.domain.dto.DomainGroupPageQry;
import com.zcloud.domain.dto.DomainGroupQry;
import com.zcloud.domain.dto.DomainGroupUpdateCmd;
import com.zcloud.domain.dto.clientobject.DomainGroupCO;
import com.zcloud.domain.dto.clientobject.DomainGroupInfoCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * web-adapter
 *
 * @Author zhaokai
 * @Date 2026-01-27 11:29:27
 */
@Api(tags = "领域组")
@RequestMapping("/${application.gateway}/domainGroup")
@RestController
@AllArgsConstructor
public class DomainGroupController {
    private final DomainGroupServiceI domainGroupService;

    @ApiOperation("领域组新增")
    @PostMapping("/save")
    public SingleResponse<DomainGroupCO> add(@Validated @RequestBody DomainGroupAddCmd cmd) {
        return domainGroupService.add(cmd);
    }
    @ApiOperation("领域组修改")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody DomainGroupUpdateCmd domainGroupUpdateCmd) {
        domainGroupService.edit(domainGroupUpdateCmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("领域组分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('lyzgl')")
    public PageResponse<DomainGroupCO> page(@RequestBody DomainGroupPageQry qry) {
        return domainGroupService.listPage(qry);
    }

    @ApiOperation("领域组所有数据")
    @PostMapping("/listAll")
    public MultiResponse<DomainGroupCO> listAll(@RequestBody DomainGroupQry qry) {
        return MultiResponse.of(domainGroupService.listAll(qry));
    }

    @ApiOperation("详情")
    @GetMapping("/getInfoById/{id}")
    public SingleResponse<DomainGroupInfoCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(domainGroupService.getInfoById(id));
    }

    @ApiOperation("删除")
    @GetMapping("/remove/{id}")
    public Response remove(@PathVariable("id") Long id) {
        domainGroupService.remove(id);
        return SingleResponse.buildSuccess();
    }


}

