package com.persagy.proxy.dictionary.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.persagy.proxy.dictionary.model.AdmModelKey;
import com.persagy.proxy.adm.request.AdmQueryCriteria;
import com.persagy.proxy.adm.request.AdmResponse;
import com.persagy.proxy.dictionary.service.IAdmModelKeyService;
import com.persagy.proxy.adm.utils.AdmContextUtil;
import com.persagy.proxy.common.entity.DmpResult;
import com.persagy.proxy.common.entity.InstanceUrlParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 模型操作
 * @author lvxy
 * @date 2021/8/25
 */
@RestController
@RequestMapping("/model")
public class AdmModelController {

    @Autowired
    private IAdmModelKeyService service;

    /**
     * 模型文件下载地址 key
     */
    @PostMapping("/key")
    public AdmResponse count(@RequestBody AdmQueryCriteria request) {
        InstanceUrlParam context = AdmContextUtil.toDmpContext();
        if(StrUtil.isBlank(context.getProjectId())) {
            return AdmResponse.failure("项目 id 不能为空");
        }
        DmpResult<JSONArray> result = service.doQuery(context, request);
        return AdmResponse.fromDmp(request, result, AdmModelKey.class);
    }
}
