package com.njcn.rdms.module.project.controller.admin.product;

import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.module.project.controller.admin.product.vo.member.ProductMemberBatchCreateReqVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.member.ProductMemberBatchInactiveReqVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.member.ProductMemberInactiveReqVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.member.ProductMemberRespVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.member.ProductMemberSaveReqVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.member.ProductMemberUpdateReqVO;
import com.njcn.rdms.module.project.service.product.ProductMemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.njcn.rdms.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 产品团队")
@RestController
@RequestMapping("/project/product")
@Validated
public class ProductMemberController {

    @Resource
    private ProductMemberService productMemberService;

    @GetMapping("/{id}/members")
    @Operation(summary = "获取产品团队成员列表")
    @Parameter(name = "id", description = "产品编号", required = true, example = "1024")
    public CommonResult<List<ProductMemberRespVO>> getProductMemberList(@PathVariable("id") Long productId) {
        return success(productMemberService.getProductMemberList(productId));
    }

    @PostMapping("/{id}/members")
    @Operation(summary = "新增产品团队成员")
    @Parameter(name = "id", description = "产品编号", required = true, example = "1024")
    public CommonResult<Long> createProductMember(@PathVariable("id") Long productId,
                                                  @Valid @RequestBody ProductMemberSaveReqVO reqVO) {
        return success(productMemberService.createProductMember(productId, reqVO));
    }

    @PostMapping("/{id}/members/batch")
    @Operation(summary = "批量新增产品团队成员")
    @Parameter(name = "id", description = "产品编号", required = true, example = "1024")
    public CommonResult<List<Long>> batchCreateProductMembers(@PathVariable("id") Long productId,
                                                              @Valid @RequestBody ProductMemberBatchCreateReqVO reqVO) {
        return success(productMemberService.batchCreateProductMembers(productId, reqVO));
    }

    @PutMapping("/{id}/members/{memberId}")
    @Operation(summary = "调整产品团队成员角色")
    public CommonResult<Boolean> updateProductMember(@PathVariable("id") Long productId,
                                                     @PathVariable("memberId") Long memberId,
                                                     @Valid @RequestBody ProductMemberUpdateReqVO reqVO) {
        productMemberService.updateProductMember(productId, memberId, reqVO);
        return success(true);
    }

    @PostMapping("/{id}/members/{memberId}/inactive")
    @Operation(summary = "移出产品团队成员")
    public CommonResult<Boolean> inactiveProductMember(@PathVariable("id") Long productId,
                                                       @PathVariable("memberId") Long memberId,
                                                       @Valid @RequestBody ProductMemberInactiveReqVO reqVO) {
        productMemberService.inactiveProductMember(productId, memberId, reqVO);
        return success(true);
    }

    @PostMapping("/{id}/members/batch/inactive")
    @Operation(summary = "批量移出产品团队成员")
    @Parameter(name = "id", description = "产品编号", required = true, example = "1024")
    public CommonResult<Boolean> batchInactiveProductMembers(@PathVariable("id") Long productId,
                                                             @Valid @RequestBody ProductMemberBatchInactiveReqVO reqVO) {
        productMemberService.batchInactiveProductMembers(productId, reqVO);
        return success(true);
    }

}
