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

import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.framework.common.pojo.PageResult;
import com.njcn.rdms.module.project.controller.admin.product.vo.activity.ProductActivityPageReqVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.activity.ProductActivityRespVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.activity.ProductActivityTimelinePageReqVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.activity.ProductActivityTimelineRespVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.setting.ProductSettingBaseInfoUpdateReqVO;
import com.njcn.rdms.module.project.controller.admin.product.vo.setting.ProductSettingRespVO;
import com.njcn.rdms.module.project.service.product.ProductService;
import com.njcn.rdms.module.project.service.product.ProductSettingService;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@Tag(name = "管理后台 - 产品设置")
@RestController
@RequestMapping("/project/product")
@Validated
public class ProductSettingController {

    @Resource
    private ProductSettingService productSettingService;
    @Resource
    private ProductService productService;

    @GetMapping("/{id}/settings")
    @Operation(summary = "获取产品设置")
    @Parameter(name = "id", description = "产品编号", required = true, example = "1024")
    public CommonResult<ProductSettingRespVO> getProductSettings(@PathVariable("id") Long id) {
        return success(productSettingService.getProductSettings(id));
    }

    @GetMapping("/{id}/activities")
    @Operation(summary = "获取产品动态")
    @Parameter(name = "id", description = "产品编号", required = true, example = "1024")
    public CommonResult<PageResult<ProductActivityRespVO>> getProductActivities(@PathVariable("id") Long id,
                                                                                @Valid ProductActivityPageReqVO reqVO) {
        return success(productSettingService.getProductActivities(id, reqVO));
    }

    @GetMapping("/{id}/activities/page")
    @Operation(summary = "获取产品动态时间线分页")
    @Parameter(name = "id", description = "产品编号", required = true, example = "1024")
    public CommonResult<PageResult<ProductActivityTimelineRespVO>> getProductActivityTimelinePage(
            @PathVariable("id") Long id, @Valid ProductActivityTimelinePageReqVO reqVO) {
        return success(productSettingService.getProductActivityTimelinePage(id, reqVO));
    }

    @PutMapping("/{id}/settings/base-info")
    @Operation(summary = "更新产品设置基础信息")
    @Parameter(name = "id", description = "产品编号", required = true, example = "1024")
    public CommonResult<Boolean> updateProductBaseInfo(@PathVariable("id") Long id,
                                                        @Valid @RequestBody ProductSettingBaseInfoUpdateReqVO reqVO) {
        productService.updateProductBaseInfo(id, reqVO);
        return success(true);
    }

}
