package com.zhongshu.card.server.core.domain.org;

import cn.hutool.json.JSONObject;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.type.CertificateType;
import com.zhongshu.card.client.type.OrganizationUserType;
import com.zhongshu.card.client.type.Sex;
import com.zhongshu.card.client.type.UserState;
import com.zhongshu.card.server.core.domain.base.SuperMain;
import com.zhongshu.card.server.core.domain.school.DictInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

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

/**
 * 用户加入的机构
 *
 * @author TRX
 * @date 2024/5/30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document
@EqualsAndHashCode(callSuper = true)
@Builder
@CompoundIndexes({@CompoundIndex(name = "organization_user", def = "{'organization': 1, 'user': 1, 'projectOid': 1 }", unique = true)})
public class OrganizationUser extends SuperMain {

    @Schema(description = "机构信息")
    @Indexed
    @DBRef(lazy = true)
    private Organization organization;

    @Schema(description = "用户信息")
    @Indexed
    @DBRef(lazy = true)
    private UserAccount user;

    //---------------------------用户基础信息 start ----------------------
    @Schema(description = "用户ID")
    private String userId;

    @Schema(description = "工号、编码")
    @Indexed
    private String code;

    @Schema(description = "用户手机号")
    @Indexed
    private String phone;

    @Schema(description = "姓名")
    @Indexed
    private String name;

    @Schema(description = "性别")
    private Sex sex;

    @Schema(description = "用户在机构的类型 学生 老师")
    private OrganizationUserType userType;

    @Schema(description = "证件类型")
    private CertificateType certificateType = CertificateType.IDCard;

    @Schema(description = "证件号码")
    private String cardNumber;

    @Schema(description = "职位")
    private DictInfo position;

    @Schema(description = "人脸照片")
    private List<String> faceImages;

    //---------------------------用户基础信息 end ------------------------

    @Schema(description = "用户状态")
    private UserState state = UserState.Normal;

    @Schema(description = "是否是企业管理员")
    private Boolean isAdmin = Boolean.FALSE;

    @Schema(description = "机构类型")
    private AuthType authType = AuthType.Enterprise;

    @Schema(description = "角色信息")
    @DBRef(lazy = true)
    private List<Role> roles = new ArrayList<>();

    @Schema(description = "角色IDs")
    private List<String> roleIds = new ArrayList<>();

    @Schema(description = "部门信息")
    @DBRef(lazy = true)
    private Department department;

    @Schema(description = "是否是机构类型，如果用户只加入项目，没加入项目的机构中，则isOrg：false")
    private Boolean isOrg = Boolean.FALSE;

    @Schema(description = "扩展字段，动态字段， {'key': 'code','value: '李四', 'filedName': '学号'}")
    private JSONObject extendData = new JSONObject();

}
