package com.yuchen.saas.manage.system.api.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yuchen.saas.manage.system.api.entity.Region;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.nest.springwrap.core.tool.node.INode;
import org.nest.springwrap.core.tool.utils.Func;

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


@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "RegionVO对象", description = "行政区划表")
public class RegionVO extends Region implements INode<RegionVO> {
    private static final long serialVersionUID = 1L;


    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;


    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;


    private String parentName;


    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Boolean hasChildren;


    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<RegionVO> children;

    @Override
    public Long getId() {
        return Func.toLong(this.getCode());
    }

    @Override
    public Long getParentId() {
        return Func.toLong(this.getParentCode());
    }

    @Override
    public List<RegionVO> getChildren() {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        return this.children;
    }
}
