package com.zhongshu.card.server.core.controller.openAPI.org;

import com.github.microservice.net.ResultContent;
import com.github.microservice.staticVariable.OpenApiMark;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.school.ImportResultModel;
import com.zhongshu.card.client.openApi.base.PhoneParam;
import com.zhongshu.card.client.openApi.base.ProjectCodeParam;
import com.zhongshu.card.client.openApi.model.orgUser.OrganizationUserOpenApiModel;
import com.zhongshu.card.client.openApi.model.orgUser.OrganizationUserOpenApiSearch;
import com.zhongshu.card.server.core.service.openAPI.org.OrganizationUserOpenApiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/" + OpenApiMark.fullCardOpenAPI + "/v1/projectUserManager")
@Tag(name = "openAPI-项目用户")
public class OrganizationUserOpenApiController {

    @Autowired
    private OrganizationUserOpenApiService organizationUserOpenApiService;

    @RequestMapping(value = "importProjectUsers", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, method = RequestMethod.POST)
    @Operation(summary = "导入项目用户", description = "导入项目用户")
    public ResultContent<ImportResultModel> importProjectUsers(
            HttpServletRequest request, HttpServletResponse response,
            @RequestPart("file") MultipartFile file, ProjectCodeParam param) throws IOException {
        if (file == null || file.isEmpty()) {
            return ResultContent.buildFail("文件不能为空");
        }
        return organizationUserOpenApiService.importProjectUsers(request, response, file, param);
    }

    @Operation(summary = "项目用户列表-分页查询", description = "项目用户列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<OrganizationUserOpenApiModel>> page(@RequestBody OrganizationUserOpenApiSearch param) {
        return organizationUserOpenApiService.projectUserPage(param);
    }

    @Operation(summary = "根据ID查询用户详情", description = "根据ID查询用户详情")
    @RequestMapping(value = {"getUserDetailById"}, method = {RequestMethod.POST})
    public ResultContent<OrganizationUserOpenApiModel> getUserDetailById(@RequestBody IDParam param) {
        return organizationUserOpenApiService.getUserDetailById(param.getId());
    }

    @Operation(summary = "手机号码精确查询用户详情", description = "手机号码精确查询用户详情")
    @RequestMapping(value = {"getUserDetailByPhone"}, method = {RequestMethod.POST})
    public ResultContent<OrganizationUserOpenApiModel> getUserDetailByPhone(
            @RequestBody PhoneParam param) {
        return organizationUserOpenApiService.getUserDetailByPhone(param);
    }

}
