package com.red.circle.other.inner.model.cmd.user;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.red.circle.framework.dto.Command;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * @author pengliang on 2020/10/21
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class UserRelationsCalculatorCmd extends Command {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 用户id.
   *
   * @eo.required
   */
  @NotNull(message = "userId required.")
  @JsonSerialize(using = ToStringSerializer.class)
  private Long userId;

  /**
   * 订阅用户.
   *
   * @eo.required
   */
  @NotNull(message = "subUserId required.")
  @JsonSerialize(using = ToStringSerializer.class)
  private Long subUserId;

  /**
   * 类型.
   *
   * @eo.required
   */
  @NotNull(message = "type required.")
  private UserRelationsCalculatorCmd.CounterEnum type;

  /**
   * 是否累计否则-减.
   */
  private Boolean incr;

  public boolean checkIncrement() {
    return Objects.equals(incr, Boolean.TRUE);
  }

  public boolean checkFriend() {
    return CounterEnum.FRIEND.eq(type);
  }

  public boolean checkInterview() {
    return CounterEnum.INTERVIEW.eq(type);
  }

  public boolean checkFans() {
    return CounterEnum.FANS.eq(type);
  }

  public boolean checkSubscription() {
    return CounterEnum.SUBSCRIPTION.eq(type);
  }

  public enum CounterEnum {

    /**
     * 关注订阅.
     */
    SUBSCRIPTION,

    /**
     * 粉丝.
     */
    FANS,

    /**
     * 朋友.
     */
    FRIEND,

    /**
     * 访客.
     */
    INTERVIEW;

    public boolean eq(String name) {
      return Objects.equals(name, this.name());
    }

    public boolean eq(CounterEnum type) {
      return Objects.equals(type, this);
    }

  }

}
