package com.eshore.gringotts.web;

import com.eshore.gringotts.web.domain.base.controller.query.Query;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.eclipsecollections.EclipseCollectionsModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

/**
 * @author lanyuanxiaoyao
 * @date 2024-12-03
 */
public class TestQueryParse {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new EclipseCollectionsModule());
        mapper.registerModule(new JavaTimeModule());
        // language=JSON
        System.out.println(mapper.readValue("{}", Query.class));
        // language=JSON
        System.out.println(mapper.readValue("{\n" +
                                            "  \"query\": {\n" +
                                            "    \"equal\": {\n" +
                                            "      \"name\": \"lanyuanxiaoyao\"\n" +
                                            "    }\n" +
                                            "  }\n" +
                                            "}", Query.class));
        // language=JSON
        System.out.println(mapper.readValue("{\n" +
                                            "  \"query\": {\n" +
                                            "    \"equal\": {\n" +
                                            "      \"name\": \"lanyuanxiaoyao\"\n" +
                                            "    },\n" +
                                            "    \"notEqual\": {\n" +
                                            "      \"username\": \"lanyuanxiaoyao@qq.com\",\n" +
                                            "      \"password\": \"mingland87\"\n" +
                                            "    },\n" +
                                            "    \"great\": {\n" +
                                            "      \"age\": 12,\n" +
                                            "      \"createTime\": \"2020-10-12 00:00:00\"\n" +
                                            "    },\n" +
                                            "    \"in\": {\n" +
                                            "      \"age\": [\n" +
                                            "        15,\n" +
                                            "        18,\n" +
                                            "        20\n" +
                                            "      ]\n" +
                                            "    },\n" +
                                            "    \"between\": {\n" +
                                            "      \"createTime\": {\n" +
                                            "        \"start\": \"2024-12-03 00:00:00\",\n" +
                                            "        \"end\": \"2024-12-03 00:00:00\"\n" +
                                            "      }\n" +
                                            "    }\n" +
                                            "  },\n" +
                                            "  \"sort\": [\n" +
                                            "    {\n" +
                                            "      \"column\": \"createTime\",\n" +
                                            "      \"direction\": \"ASC\"\n" +
                                            "    }\n" +
                                            "  ],\n" +
                                            "  \"page\": {\n" +
                                            "    \"size\": 10,\n" +
                                            "    \"page\": 1\n" +
                                            "  }\n" +
                                            "}", Query.class));
    }
}
