package com.neusoft.smart.pos.ssl.controller;


import com.neusoft.smart.pos.dto.ssl.request.SSLIssueRequest;
import com.neusoft.smart.pos.dto.ssl.response.SSLFileResponse;
import com.neusoft.smart.pos.ssl.service.SSLService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "广告策略管理restful接口", description = "广告策略管理restful接口")
@RestController
@Slf4j
public class SSLController {
	
	@Autowired
	private SSLService sslService;
	
	@PostMapping("/OTA/issue/certificates")
	@ApiOperation(value = "发放密钥接口", notes = "发放密钥接口")
	public SSLFileResponse issueCertificates(@RequestBody SSLIssueRequest sslIssueRequest) {
		String randomStr = sslIssueRequest.getRandomString();
		String sn = sslIssueRequest.getSn();
		SSLFileResponse sslFileResponse = new SSLFileResponse();
		try {
			sslFileResponse = sslService.issue(randomStr, sn);
			sslFileResponse.setStatus(200);
		} catch (Exception e) {
			sslFileResponse.setStatus(500);
			sslFileResponse.setMsg(e.getMessage());
		}
		log.info("get cert file");
		return sslFileResponse;
	}
	
}
