package com.emoon.openplatform.controller;

import com.emoon.common.core.domain.R;
import com.emoon.openplatform.domain.ModelDo;
import com.emoon.openplatform.domain.SysProjectDo;
import com.emoon.openplatform.service.IModelService;
import com.emoon.openplatform.service.ISysProjectService;
import lombok.RequiredArgsConstructor;
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 java.util.List;

/**
 * @author destiny
 * @description:
 * @date 2025/10/25 23:30
 */
@RestController
@RequestMapping("/model")
@RequiredArgsConstructor
public class ModelController {

    private final ISysProjectService sysProjectService;

    private final IModelService modelService;

    /**
     * 供三方系统所支持的模型信息
     *
     * @param publicKey
     * @return
     */
    @GetMapping("/search")
    public R<List<ModelDo>> search(@RequestParam String publicKey) {
        SysProjectDo sysProjectDo = sysProjectService.queryByPublicKey(publicKey);
        if (sysProjectDo == null) {
            return R.fail("该公钥并未配置模型权限，请联系管理员添加！");
        }
        return R.ok(modelService.queryByIds(sysProjectDo.getModelIds()));
    }

}
