package com.red.circle.common.business.dto.cmd;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.common.business.enums.PlatformChannelEnum;
import com.red.circle.framework.core.dto.AppCommand;
import com.red.circle.framework.core.dto.ReqAppIntel;
import com.red.circle.tool.core.date.DateUtils;
import java.io.Serial;
import java.util.Date;
import java.util.Objects;

import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * app命令扩展.
 *
 * @author pengliang on 2023/8/18
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class AppExtCommand extends AppCommand {

  @Serial
  private static final long serialVersionUID = 1L;

  private String roomSessionId;

    /**
     * 所有区域
     */
  private boolean isAllRegion = false;

  /**
   * 转系统枚举.
   */
  public SysOriginPlatformEnum requireReqSysOriginEnum() {
    return SysOriginPlatformEnum.valueOf(requireReqSysOrigin());
  }

  /**
   * 转系统枚举.
   */
  public SysOriginPlatformEnum requireReqSysOriginChildEnum() {
    return SysOriginPlatformEnum.valueOf(requireReqSysOriginChild());
  }

  /**
   * 转请求渠道枚举.
   */
  public PlatformChannelEnum reqPlatformChannelEnum() {
    return PlatformChannelEnum.valueOf(getReqAppIntel().getChannel());
  }

  /**
   * 编译版本号.
   */
  public int buildVersion() {
    ReqAppIntel reqAppIntel = getReqAppIntel();
    if (Objects.isNull(reqAppIntel)) {
      return -1;
    }
    return Objects.isNull(reqAppIntel.getBuild()) ? -1 : reqAppIntel.getBuild();
  }

  /**
   * 来源是否是aswat.
   */
  public boolean originEqAswat() {
    return Objects.equals(SysOriginPlatformEnum.ASWAT, requireReqSysOriginEnum());
  }

  /**
   * 来源是否是2fun.
   */
  public boolean originEq2Fun() {
    return Objects.equals(SysOriginPlatformEnum.TWO_FUN, requireReqSysOriginEnum());
  }

  /**
   * 来源是否是Tarab.
   */
  public boolean originEqTarab() {
    return Objects.equals(SysOriginPlatformEnum.TARAB, requireReqSysOriginEnum());
  }

  /**
   * 来源是否是yolo.
   */
  public boolean originEqYolo() {
    return Objects.equals(SysOriginPlatformEnum.YOLO, requireReqSysOriginEnum());
  }

  /**
   * 获取请求为null,等于当前时间.
   */
  public Date reqTimeElseNow() {
    return Objects.isNull(getReqTime()) ? DateUtils.now() : getReqTime();
  }

  /**
   * 获取请求为null,等于当前时间.
   */
  public boolean reqVersionIsGameNew() {
    return false;
  }

  public boolean reqVersionIs191() {
    return Integer.parseInt(getReqAppIntel().getVersion().replace(".", "")) >= 191;

  }



}
