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

import com.hz.pm.api.projectdeclared.manage.ReviewByProvincialDeptManage;
import com.hz.pm.api.projectlib.model.entity.Project;
import com.hz.pm.api.provincial.model.res.SjApiResponse;
import com.hz.pm.api.provincial.service.IJoinReviewProvincialBureauService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.io.IOException;
import java.io.InputStream;

/**
 * @Classname TestController
 * @Description
 * @Date 2023/3/2 15:08
 * @Author PoffyZhang
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/test")
@Api(tags = "测试省局接口")
public class TestController {

    private final IJoinReviewProvincialBureauService joinReviewProvincialBureauService;
    private final ReviewByProvincialDeptManage provincialDeptManage;

    @GetMapping("/push")
    @ApiOperation("测试推送")
    public Boolean push(@Valid @RequestParam Long projectId) {
        Project project = new Project();
        project.setId(projectId);
        return provincialDeptManage.startTheProcess(project);
    }

    @GetMapping("/detail")
    @ApiOperation("测试获取详情")
    public SjApiResponse detail(@RequestParam String projectId) {
        return joinReviewProvincialBureauService.processInfo(projectId);
    }

    @GetMapping("/path")
    @ApiOperation("测试获取详情")
    public String path() throws IOException {
        InputStream in = this.getClass().getResourceAsStream("/template/simsun.ttc");
        StringBuilder sb = new StringBuilder();
        int n;
        while ((n = in.read()) != -1) {
            sb.append((char) n);
        }

        return sb.toString();
    }
}
