package com.dfem.pms.controller.gitea;


import cn.dev33.satoken.annotation.SaIgnore;
import com.dfem.pms.es.mapper.TestDocMapper;
import com.dfem.pms.es.model.TestDoc;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/pms/gitea")
public class GiteaController {
    @Resource
    private final TestDocMapper testDocMapper;
    private final RestHighLevelClient restHighLevelClient;

    @SaIgnore
    @PostMapping("/commitContent")
    public R<Void> testContent(@RequestBody String body) {
        log.debug(body);
        return R.ok();
    }

    @SaIgnore
    @GetMapping("/createIndex")
    private R<String> createEsIndex() {
        testDocMapper.createIndex();
        return R.ok("Success");
    }

    @SaIgnore
    @GetMapping("/insert")
    private R<Integer> insert() {
        for (int i = 0; i < 9999; i++) {
            TestDoc doc = new TestDoc();
            doc.setId(String.valueOf(i));
            doc.setTitle("老汉" + i);
            doc.setContent("hello world my name is test laohantuiche" + i);
            testDocMapper.insert(doc);
        }
        return R.ok(9999);
    }

    @SaIgnore
    @GetMapping("/list")
    private R<List<TestDoc>> list() {
        LambdaEsQueryWrapper<TestDoc> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.match(TestDoc::getContent, "hello");
        return R.ok(testDocMapper.selectList(wrapper));
    }

}
