package thyyxxk.webserver.controller.dictionary;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.constants.sidicts.PsnCertType;
import thyyxxk.webserver.dao.his.dictionary.FetchDictionariesDao;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.utils.ResultVoUtil;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/fetchDictionaries")
public class FetchDictionariesController {
    private final FetchDictionariesDao dao;

    @Autowired
    public FetchDictionariesController(FetchDictionariesDao dao) {
        this.dao = dao;
    }

    @GetMapping("/country")
    public ResultVo<List<CodeName>> selectCountries() {
        return ResultVoUtil.success(dao.selectCountries());
    }

    @GetMapping("/nation")
    public ResultVo<List<CodeName>> selectNations() {
        return ResultVoUtil.success(dao.selectNations());
    }

    @GetMapping("/relation")
    public ResultVo<List<CodeName>> selectRelations() {
        return ResultVoUtil.success(dao.selectRelations());
    }

    @GetMapping("/psnCertType")
    public ResultVo<List<CodeName>> selectPsnCertTypes() {
        List<CodeName> list = new ArrayList<>();
        for (PsnCertType psnCertType : PsnCertType.values()) {
            list.add(new CodeName(psnCertType.getCode(), psnCertType.getName()));
        }
        return ResultVoUtil.success(list);
    }
}
