package com.zt.plat.module.base.api.materialinfomation.dto;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

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

/**
 * 物料信息 Response DTO
 */
@Data
public class MaterialInfomationRespDTO {

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "3326")
    private Long id;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Schema(description = "物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
    private String code;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Schema(description = "物料名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
    private String name;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Schema(description = "分类ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Long classesId;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED)
    private String remark;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime createTime;

    @JsonIgnore
    @Schema(description = "物料基础字段 + 属性编码->原值的动态键值")
    private Map<String, Object> flatAttributes = new LinkedHashMap<>();

    @JsonAnyGetter
    public Map<String, Object> getFlatAttributes() {
        return flatAttributes;
    }

    @JsonAnySetter
    public void addAttribute(String key, Object value) {
        if (flatAttributes == null) {
            flatAttributes = new LinkedHashMap<>();
        }
        flatAttributes.put(key, value);
    }
}