package shop.alien.entity.store.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import shop.alien.entity.store.LifeSysDept;

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

/**
 * 部门树形结构VO
 *
 * @author system
 * @since 2025-01-XX
 */
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude
@ApiModel(value = "LifeSysDeptVo对象", description = "部门树形结构")
public class LifeSysDeptVo extends LifeSysDept {

    @ApiModelProperty(value = "子部门列表")
    private List<LifeSysDeptVo> children;

    @ApiModelProperty(value = "部门人员数量（包含子部门）")
    private Integer memberCount;

    @ApiModelProperty(value = "当前部门人数")
    private Integer currentMemberCount;

    public LifeSysDeptVo() {
        this.children = new ArrayList<>();
        this.memberCount = 0;
        this.currentMemberCount = 0;
    }

    /**
     * 从LifeSysDept转换为LifeSysDeptVo
     *
     * @param dept 部门实体
     * @return LifeSysDeptVo
     */
    public static LifeSysDeptVo fromEntity(LifeSysDept dept) {
        if (dept == null) {
            return null;
        }
        LifeSysDeptVo vo = new LifeSysDeptVo();
        vo.setDeptId(dept.getDeptId());
        vo.setParentId(dept.getParentId());
        vo.setAncestors(dept.getAncestors());
        vo.setDeptName(dept.getDeptName());
        vo.setDeptSort(dept.getDeptSort());
        vo.setLeader(dept.getLeader());
        vo.setPhone(dept.getPhone());
        vo.setEmail(dept.getEmail());
        vo.setStatus(dept.getStatus());
        vo.setDelFlag(dept.getDelFlag());
        vo.setCreateBy(dept.getCreateBy());
        vo.setCreatedTime(dept.getCreatedTime());
        vo.setUpdateBy(dept.getUpdateBy());
        vo.setUpdatedTime(dept.getUpdatedTime());
        vo.setDescription(dept.getDescription());
        vo.setChildren(new ArrayList<>());
        vo.setMemberCount(0); // 初始化为0，后续会通过统计方法计算
        vo.setCurrentMemberCount(0); // 初始化为0，后续会通过统计方法计算
        return vo;
    }
}

