package com.red.circle.other.infra.enums.family;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 家族动态类型枚举
 */
@Getter
@RequiredArgsConstructor
public enum FamilyNewsTypeEnum {

  /**
   * 成员加入家族
   */
  MEMBER_JOIN("MEMBER_JOIN", "[{targetUserName}] joined the family."),

  /**
   * 成员被授权为管理员
   */
  MEMBER_PROMOTED_ADMIN("MEMBER_PROMOTED_ADMIN", "[{targetUserName}] become an admin."),

  /**
   * 成员被取消管理员
   */
  MEMBER_DEMOTED("MEMBER_DEMOTED", "[{targetUserName}] was removed from admin."),

  /**
   * 成员被族长踢出家族
   */
  MEMBER_KICKED_ADMIN("MEMBER_KICKED", "[{targetUserName}] has been removed from the family by the family owner."),

  /**
   * 成员被管理员踢出家族
   */
  MEMBER_KICKED_MANAGE("MEMBER_KICKED", "[{targetUserName}] has been removed from the family by the family admin."),


  /**
   * 成员主动退出
   */
  MEMBER_LEFT("MEMBER_LEFT", "[{targetUserName}] has left the family."),

  /**
   * 家族资料修改
   */
  FAMILY_INFO_EDIT("FAMILY_INFO_EDIT", "Family information has been updated."),

  /**
   * 家族公告修改
   */
  FAMILY_NOTICE_EDIT("FAMILY_NOTICE_EDIT", "The family announcement has been updated."),

  /**
   * 家族解散
   */
  FAMILY_DISBANDED("FAMILY_DISBANDED", "The family [{targetFamilyName}] has been disbanded.");

  private final String code;
  private final String template;

  /**
   * 生成动态文本
   */
  public String generateContent(String targetUserName) {
    if (this == FAMILY_INFO_EDIT || this == FAMILY_NOTICE_EDIT) {
      return template;
    }
    
    if (this == FAMILY_DISBANDED) {
      return template.replace("{targetFamilyName}", targetUserName != null ? targetUserName : "");
    }
    
    String displayName = targetUserName;
    if (targetUserName != null && targetUserName.length() > 12) {
      displayName = targetUserName.substring(0, 12) + "...";
    }
    
    return template.replace("{targetUserName}", displayName != null ? displayName : "");
  }
}
