package incheon.ags.mrb.chart.web.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import incheon.ags.mrb.chart.vo.ChartQueryVO;

import java.util.List;

@lombok.Getter @lombok.Setter
public class ChartQueryParams {

    // ChartQueryParams.java 수정된 부분
    @Schema(description = "차트 타입 (histogram, bar, pie, line, box)", example = "box", required = true)
    @NotBlank(message = "Chart type is required")
    private String chartType;

    @Schema(description = "숫자 필드 (히스토그램용)", example = "jcount")
    private String numberField;

    @Schema(description = "Bin 개수 (히스토그램용)", example = "32")
    @NotNull(message = "Bin count is required for histogram chart type")
    private Integer binCount; // Integer로 변경, null 허용 가능

    @Schema(description = "그룹화 기준 필드 (바차트/파이차트/선형/박스플롯용)", example = "period")
    @NotBlank(message = "Category is required for bar, pie, or line chart")
    private String category;

    @Schema(description = "집계 함수 (바차트/파이차트용)", example = "count")
    @NotBlank(message = "Aggregation is required for bar or pie chart")
    private String aggregation;

    @Schema(description = "값 필드 목록 (바차트/파이차트/선형/박스플롯용)", example = "[\"jcount\"]", required = true)
    @NotNull(message = "Values are required for bar, pie, or line chart")
    private List<String> values;

    @Schema(description = "분할 기준 필드 (선택)", example = "null")
    private String split;

    @Schema(description = "정렬 방향 (asc/desc/avgasc/avgdesc/medianasc/mediandesc)", example = "desc")
    private String sort;

    @Schema(description = "모드 (category/field)", example = "field")
    private String mode;

    @Schema(description = "값 표준화 (Z-Score) 적용 여부", example = "false")
    private Boolean zScore = false;

    @Schema(description = "이상치 표시 여부", example = "true")
    private Boolean showOutliers = true;

    @Schema(description = "레이어 ID", example = "layer_123")
    private String layerId;

    @Schema(description = "레이어 타입 (TASK/USER)", example = "TASK")
    private String layerType;

    @Schema(description = "물리 테이블명 (schema.table)", example = "public.incheon_bus_stations")
    private String tableName;

    // VO로 변환 (필요 시 VO 클래스 정의 후 사용)
    public ChartQueryVO toEntity() {
        ChartQueryVO vo = new ChartQueryVO();
        vo.setChartType(this.chartType);
        vo.setNumberField(this.numberField);
        vo.setBinCount(this.binCount);
        vo.setCategory(this.category);
        vo.setAggregation(this.aggregation);
        vo.setValues(this.values);
        vo.setSplit(this.split);
        vo.setSort(this.sort);
        vo.setMode(this.mode);
        return vo;
    }
}