package com.zcloud.basic.info.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.basic.info.api.UserCorpServiceI;
import com.zcloud.basic.info.dto.UserCorpAddCmd;
import com.zcloud.basic.info.dto.UserCorpPageQry;
import com.zcloud.basic.info.dto.UserCorpUpdateCmd;
import com.zcloud.basic.info.dto.clientobject.UserCorpCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * web-adapter
 *
 * @Author zhaokai
 * @Date 2025-12-02 11:13:33
 */
@Api(tags = "用户企业表")
@RequestMapping("/${application.gateway}/userCorp")
@RestController
@AllArgsConstructor
public class UserCorpController {
    private final UserCorpServiceI userCorpService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<UserCorpCO> add(@Validated @RequestBody UserCorpAddCmd cmd) {
        SSOUser ssoUser = AuthContext.getCurrentUser();
        return userCorpService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<UserCorpCO> page(@RequestBody UserCorpPageQry qry) {
        return userCorpService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @GetMapping("/listAll")
    public MultiResponse<UserCorpCO> listAll() {
        return MultiResponse.of(new ArrayList<UserCorpCO>());
    }

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

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

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

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody UserCorpUpdateCmd userCorpUpdateCmd) {
        userCorpService.edit(userCorpUpdateCmd);
        return SingleResponse.buildSuccess();
    }
}

