package com.gxwebsoft.common.core.controller;

import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * Jackson序列化测试控制器
 * 用于测试LocalDateTime序列化是否正常工作
 *
 * @author WebSoft
 * @since 2025-09-08
 */
@Tag(name = "Jackson测试")
@RestController
@RequestMapping("/api/test/jackson")
public class JacksonTestController extends BaseController {

    @Operation(summary = "测试LocalDateTime序列化")
    @GetMapping("/datetime")
    public ApiResult<Map<String, Object>> testDateTime() {
        Map<String, Object> result = new HashMap<>();
        result.put("currentTime", LocalDateTime.now());
        result.put("message", "如果您能看到格式化的时间，说明Jackson配置正常");
        result.put("timestamp", System.currentTimeMillis());
        return success(result);
    }

    @Operation(summary = "测试实体类序列化")
    @GetMapping("/entity")
    public ApiResult<TestEntity> testEntity() {
        TestEntity entity = new TestEntity();
        entity.setId(1);
        entity.setName("测试实体");
        entity.setCreateTime(LocalDateTime.now());
        entity.setUpdateTime(LocalDateTime.now());
        return success(entity);
    }

    /**
     * 测试实体类
     */
    public static class TestEntity {
        private Integer id;
        private String name;
        private LocalDateTime createTime;
        private LocalDateTime updateTime;

        // Getters and Setters
        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public LocalDateTime getCreateTime() {
            return createTime;
        }

        public void setCreateTime(LocalDateTime createTime) {
            this.createTime = createTime;
        }

        public LocalDateTime getUpdateTime() {
            return updateTime;
        }

        public void setUpdateTime(LocalDateTime updateTime) {
            this.updateTime = updateTime;
        }
    }
}
