package com.mcwl.web.controller.resource;

import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.core.domain.R;
import com.mcwl.common.core.page.TableDataInfo;
import com.mcwl.resource.domain.ModelVersion;
import com.mcwl.resource.service.ModelVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/** 模型版本
 * @Author：ChenYan
 * @Project：McWl
 * @Package：com.mcwl.web.controller.resource
 * @Filename：ModelVersionController
 * @Description TODO
 * @Date：2025/1/9 16:47
 */
@Api(tags = "模型版本")
@RestController
@RequestMapping("ModelVersion")
public class ModelVersionController  extends BaseController {

    @Autowired
    private ModelVersionService modelVersionService;


    /**
     * 详情页 版本列表
     * @param modelId
     * @return
     */
    @GetMapping("/selectByModelId")
    public R<List<ModelVersion>> selectByModelId(@RequestParam Long modelId){

        return modelVersionService.selectByModelId(modelId);
    }

    @ApiOperation(value = "模型版本列表")
    @PostMapping("list")
    public TableDataInfo list(@RequestBody ModelVersion modelVersion)
    {
        startPage();
        List<ModelVersion> list = modelVersionService.selectLogininforList(modelVersion);
        return getDataTable(list);
    }


    @ApiOperation(value = "模型版本详情")
    @GetMapping("finbyid")
    public R<List<ModelVersion>> finbyid(@RequestParam Long id)
    {


        List<ModelVersion> modelVersionList = modelVersionService.finbyid(id);

        return R.ok(modelVersionList);
    }



    @ApiOperation(value = "模型版本添加")
    @PostMapping("insert")
    public R<Object> insert(@RequestBody ModelVersion modelVersion)
    {
        modelVersionService.save(modelVersion);
        return R.ok();
    }



    @ApiOperation(value = "模型版本修改")
    @PostMapping("update")
    public R<Object> update(@RequestBody ModelVersion modelVersion)
    {
        modelVersionService.updateById(modelVersion);
        return R.ok();
    }


    @ApiOperation(value = "模型版本删除")
    @PostMapping("delete")
    public R<Object> delete(@RequestBody ModelVersion modelVersion)
    {
        modelVersionService.removeById(modelVersion.getId());
        return R.ok();
    }

    /**
     * 下载模型文件
     * @param id
     * @return
     */
    @ApiOperation(value = "下载模型文件")
    @GetMapping("/modelFileDownload")
    public R modelFileDownload(@RequestParam Long id){

       return modelVersionService.modelFileDownload(id);
    }

}
