package com.gxwebsoft.common.system.entity;

import cn.hutool.core.util.DesensitizedUtil;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

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

/**
 * 租户
 *
 * @author 科技小王子
 * @since 2023-07-17 17:49:53
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(name = "Tenant对象", description = "租户")
@TableName("sys_tenant")
public class Tenant implements Serializable {
  private static final long serialVersionUID = 1L;

  @Schema(description = "租户id")
  @TableId(value = "tenant_id", type = IdType.AUTO)
  private Integer tenantId;

  @Schema(description = "租户名称")
  private String tenantName;

  @Schema(description = "租户编号")
  private String tenantCode;

  @Schema(description = "备注")
  private String comments;

  @Schema(description = "状态")
  private Integer status;

  @Schema(description = "排序号")
  private Integer sortNumber;

  @Schema(description = "用户ID")
  private Integer userId;

  @Schema(description = "当前订阅ID")
  private Long subscriptionId;

  @Schema(description = "是否试用中")
  private Integer isTrial;

  @Schema(description = "试用结束时间")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  private Date trialEndTime;

  @Schema(description = "自动续费")
  private Integer autoRenewal;

  @Schema(description = "是否删除, 0否, 1是")
  @TableLogic
  private Integer deleted;

  @Schema(description = "创建时间")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  private Date createTime;

  @Schema(description = "修改时间")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  private Date updateTime;

  @Schema(description = "菜单信息")
  @TableField(exist = false)
  private List<Menu> menu;

  @Schema(description = "企业信息")
  @TableField(exist = false)
  private Company company;

  @Schema(description = "企业名称")
  @TableField(exist = false)
  private String companyName;

  @Schema(description = "logo")
  @TableField(exist = false)
  private String logo;

  @Schema(description = "配置信息")
  @TableField(exist = false)
  private Object config;

  @Schema(description = "服务器时间")
  @TableField(exist = false)
  private Object date;

  @Schema(description = "用户名")
  @TableField(exist = false)
  private String username;

  @Schema(description = "手机号码")
  @TableField(exist = false)
  private String phone;

  @Schema(description = "超级管理员UID")
  @TableField(exist = false)
  private Integer ownerId;

  @Schema(description = "管理地址")
  @TableField(exist = false)
  private String adminUrl;

  @Schema(description = "顶级域名")
  @TableField(exist = false)
  private String domain;

  @Schema(description = "免费域名")
  @TableField(exist = false)
  private String freeDomain;

  /**
   * 是否脱敏手机号，默认true脱敏
   */
  @TableField(exist = false)
  @Schema(description = "手机号是否脱敏，默认true")
  private boolean phoneMasked = true;

  public String getPhone(){
    if (phoneMasked) {
      return DesensitizedUtil.mobilePhone(this.phone);
    }
    return this.phone;
  }

  public void setPhoneMasked(boolean masked) {
    this.phoneMasked = masked;
  }
}
