package incheon.cmm.g2f.layer.vo;

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

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

import incheon.cmm.g2f.layer.domain.LayerType;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import io.swagger.v3.oas.annotations.media.Schema;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 레이어 편집 API 요청 DTO
 */
@Getter
@Setter
@NoArgsConstructor
@Schema(description = "레이어 편집 요청")
public class LayerEditRequestDTO {
    
    @Schema(description = "레이어 ID", example = "64", required = true)
    @NotBlank(message = "레이어 ID는 필수입니다.")
    @JsonProperty("layerId")
    private String layerId;

    @Schema(description = "레이어 유형 (TASK: 업무레이어, USER: 사용자레이어)",
            example = "TASK", required = true)
    @NotNull(message = "레이어 유형은 필수입니다.")
    @JsonProperty("layerType")
    private LayerType layerType;

    @Schema(description = "편집 변경사항", required = true)
    @NotNull(message = "변경사항은 필수입니다.")
    @Valid
    @JsonProperty("changes")
    private ChangesDTO changes;
    
    /**
     * 편집 변경사항 DTO
     */
    @Getter
    @Setter
    @NoArgsConstructor
    @Schema(description = "편집 변경사항")
    public static class ChangesDTO {
        
        @Schema(description = "추가된 피처 목록")
        @Valid 
        private List<FeatureVO> added = new ArrayList<>();
        
        @Schema(description = "수정된 피처 목록")
        @Valid 
        private List<FeatureVO> modified = new ArrayList<>();
        
        @Schema(description = "삭제된 피처 ID 목록", example = "[6, 2]")
        private List<Integer> deleted = new ArrayList<>();
        
        // 커스텀 setter - null 체크와 기본값 설정
        public void setAdded(List<FeatureVO> added) {
            this.added = added != null ? added : new ArrayList<>();
        }
        
        public void setModified(List<FeatureVO> modified) {
            this.modified = modified != null ? modified : new ArrayList<>();
        }
        
        public void setDeleted(List<Integer> deleted) {
            this.deleted = deleted != null ? deleted : new ArrayList<>();
        }
    }
}