package com.qqchen.deploy.backend.system.entity;

import com.qqchen.deploy.backend.framework.annotation.LogicDelete;
import com.qqchen.deploy.backend.framework.domain.Entity;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.persistence.OneToMany;
import java.util.HashSet;
import java.util.Set;

@Data
@EqualsAndHashCode(callSuper = true)
@jakarta.persistence.Entity
@Table(name = "sys_department")
@LogicDelete
public class Department extends Entity<Long> {

    @NotBlank(message = "部门名称不能为空")
    @Column(nullable = false)
    private String name;

    @NotBlank(message = "部门编码不能为空")
    @Column(nullable = false, unique = true)
    private String code;

    private String description;

    @Column(name = "parent_id")
    private Long parentId;

    @Column(nullable = false)
    private Integer sort = 0;

    @Column(nullable = false)
    private Boolean enabled = true;

    @Column(name = "leader_id")
    private Long leaderId;

    @Column(name = "leader_name")
    private String leaderName;

    @OneToMany(mappedBy = "department", fetch = FetchType.LAZY)
    private Set<User> users = new HashSet<>();

}