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.DomainDepartmentServiceI;
import com.zcloud.domain.dto.DomainDepartmentAddCmd;
import com.zcloud.domain.dto.DomainDepartmentPageQry;
import com.zcloud.domain.dto.DomainDepartmentUpdateCmd;
import com.zcloud.domain.dto.clientobject.DomainDepartmentCO;
import com.zcloud.domain.dto.clientobject.DomainDepartmentListCO;
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;
import java.util.List;

/**
 * web-adapter
 *
 * @Author zhaokai
 * @Date 2026-01-27 11:28:51
 */
@Api(tags = "领域部门")
@RequestMapping("/${application.gateway}/domainDepartment")
@RestController
@AllArgsConstructor
public class DomainDepartmentController {
    private final DomainDepartmentServiceI domainDepartmentService;

    @ApiOperation("领域部门新增")
    @PostMapping("/save")
    public SingleResponse<DomainDepartmentCO> add(@Validated @RequestBody DomainDepartmentAddCmd cmd) {
        return domainDepartmentService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('lybmgl')")
    public PageResponse<DomainDepartmentListCO> page(@RequestBody DomainDepartmentPageQry qry) {
        return domainDepartmentService.listPage(qry);
    }

    @ApiOperation("领域部门所有数据")
    @PostMapping("/listAll")
    public MultiResponse<DomainDepartmentCO> listAll() {
        List<DomainDepartmentCO> domainDepartmentCOList = domainDepartmentService.listAll();
        return MultiResponse.of(domainDepartmentCOList);
    }

    @ApiOperation("领域部门详情")
    @GetMapping("/getInfoById/{id}")
    public SingleResponse<DomainDepartmentCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(domainDepartmentService.getInfoById(id));
    }
    @ApiOperation("领域部门修改")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody DomainDepartmentUpdateCmd domainDepartmentUpdateCmd) {
        domainDepartmentService.edit(domainDepartmentUpdateCmd);
        return SingleResponse.buildSuccess();
    }

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

/*    @ApiOperation("删除多个")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam Long[] ids) {
        domainDepartmentService.removeBatch(ids);
        return SingleResponse.buildSuccess();
    }*/


}

