package com.pavis.admin.controller.aigc;

import com.pavis.admin.aigc.core.SpringContextHolder;
import com.pavis.admin.aigc.event.EmbeddingRefreshEvent;
import com.pavis.admin.aigc.model.query.EmbedStoreQuery;
import com.pavis.admin.aigc.model.req.EmbedStoreReq;
import com.pavis.admin.aigc.model.resp.EmbedStoreDetailResp;
import com.pavis.admin.aigc.model.resp.EmbedStoreResp;
import com.pavis.admin.aigc.service.EmbedStoreService;
import com.pavis.admin.common.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.enums.Api;
import top.continew.starter.extension.crud.model.resp.IdResp;
import top.continew.starter.extension.crud.validation.CrudValidationGroup;

/**
 * 向量存储配置管理 API
 *
 * @author semi
 * @since 2025/05/26 17:28
 */
@Tag(name = "AIGC向量存储配置管理 API")
@RestController
@CrudRequestMapping(value = "/aigc/embedStore", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE,
    Api.EXPORT})
public class EmbedStoreController extends BaseController<EmbedStoreService, EmbedStoreResp, EmbedStoreDetailResp, EmbedStoreQuery, EmbedStoreReq> {
    @Override
    @Operation(summary = "新增重载数据", description = "新增重载数据")
    public IdResp<Long> create(@Validated(CrudValidationGroup.Create.class) @RequestBody EmbedStoreReq req) {
        IdResp<Long> longIdResp = super.create(req);
        SpringContextHolder.publishEvent(new EmbeddingRefreshEvent(req));
        return longIdResp;
    }

    @Override
    @Operation(summary = "更新重载数据", description = "更新重载数据")
    public void update(@Validated(CrudValidationGroup.Create.class) @RequestBody EmbedStoreReq req,
                       @PathVariable("id") Long id) {
        super.update(req, id);
        SpringContextHolder.publishEvent(new EmbeddingRefreshEvent(req));
    }
}