package com.hz.pm.api.irs.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ningdatech.log.annotation.WebLog;
import com.hz.pm.api.irs.manage.AppIrsManage;
import com.hz.pm.api.irs.model.dto.ApiApplyDTO;
import com.hz.pm.api.irs.model.dto.PushProjectAppToIrsDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.security.NoSuchAlgorithmException;

/**
 * @Classname ApplicationController
 * @Description
 * @Date 2023/7/12 9:26
 * @Author PoffyZhang
 */
@RestController
@RequestMapping("/api/v1/irs/app")
@AllArgsConstructor
@Slf4j
@Valid
public class ApplicationController {

    private final AppIrsManage appIrsManage;

    @PostMapping("/push-project-app")
    @WebLog("推送项目和应用关系")
    public Boolean pushProjectApp(@Valid @RequestBody PushProjectAppToIrsDTO dto) throws Exception {
        return appIrsManage.pushProjectApp(dto);
    }

    @GetMapping("/sreach-app")
    public JSONObject searchApp(ApiApplyDTO apply) throws NoSuchAlgorithmException {
        return appIrsManage.searchApp(apply);
    }

    @GetMapping("/sreach-apps")
    public JSONArray searchApps(ApiApplyDTO apply) throws NoSuchAlgorithmException {
        return appIrsManage.searchApps(apply);
    }

    @GetMapping("/digitalResourcesIndicators/{appCode}/{pageSize}")
    public JSONObject getDigitalResourcesIndicators(@PathVariable String appCode,@PathVariable Integer pageSize) {
        return appIrsManage.getDigitalResourceIndicatorsByAppCode(appCode, pageSize);
    }

}
