package com.usky.sas.service.dto.agbox;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;

import java.util.List;

/**
 * AG 接口 getHouse 响应 - 房屋信息分页
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class HouseVo {

    private HouseResult result;

    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class HouseResult {
        /** 房屋列表 */
        private List<HouseList> houseList;
        /** 当前页数量 */
        private Long count;
        /** 当前页码 */
        private Integer page;
        /** 每页数量 */
        private Integer pageSize;
        /** 总页数 */
        private Integer totalPage;
    }

    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class HouseList {
        private String houseCode;
        private Integer floor;
        private String houseNo;
        private String houseLabel;
        private Integer houseLabelCode;
        private Integer housePurposeCode;
        private String housePurpose;
        private String note;
        private Boolean isPublic;
        private Boolean isAction;
        private Integer systesasTypeCode;
        private String buildingCode;
        private String gisId;
        private Integer personNumber;
        private Integer houseArea;
        private String villageCode;
        /** tags 可能为字符串或数组 */
        private JsonNode tags;
        private Integer placeTypeId;
        private String houseName;
        private String updateTime;
        private String createTime;

        /** 转为字符串：数组则逗号拼接或 JSON，字符串则原样返回 */
        public String getTagsAsString() {
            if (tags == null) return null;
            if (tags.isTextual()) return tags.asText();
            if (tags.isArray()) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < tags.size(); i++) {
                    if (i > 0) sb.append(',');
                    JsonNode e = tags.get(i);
                    sb.append(e.isTextual() ? e.asText() : e.toString());
                }
                return sb.toString();
            }
            return tags.toString();
        }
    }
}
