package com.ema.admin.modules.system.vo;

import com.ema.common.utils.TreeNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 部门信息 VO。
 *
 * @author LIJIAN
 * @since 2026-05-12
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("部门信息")
public class SysDepartmentVo implements TreeNode<SysDepartmentVo, String>, Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 部门id
     */
    @ApiModelProperty("部门id")
    private String id;

    /**
     * 部门编码
     */
    @ApiModelProperty("部门编码")
    private String deptCode;

    /**
     * 部门名称
     */
    @ApiModelProperty("部门名称")
    private String deptName;

    /**
     * 上级部门ID (0为顶级部门)
     */
    @ApiModelProperty("上级部门ID")
    private String parentId;

    /**
     * 显示顺序
     */
    @ApiModelProperty("显示顺序")
    private Integer sort;

    /**
     * 下级部门
     */
    @ApiModelProperty("下级部门")
    private List<SysDepartmentVo> children;

    @Override
    public void addChild(SysDepartmentVo child) {
        if (children == null) {
            children = new ArrayList<>();
        }
        children.add(child);
    }

    @Override
    public void setChecked(boolean checked) {
        // 部门树暂不支持选中状态
    }

    @Override
    public int compareTo(SysDepartmentVo other) {
        return this.sort == null || other.sort == null ? 0 : this.sort - other.sort;
    }

}
