package com.ruoyi.dj.mqtt.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.UUID;

@Data
@NoArgsConstructor
public class CommonFieldsVo {
    private String tid;
    private String bid;
    private String method;
    private String gateway;

    public CommonFieldsVo(String bid, String tid, String method, String gateway) {
        this.tid = tid;
        this.bid = bid;
        this.method = method;
        this.gateway = gateway;
    }

    public CommonFieldsVo(String bid, String tid, String method) {
        this.tid = tid;
        this.bid = bid;
        this.method = method;
    }

    public static CommonFieldsVo createCommonFieldVo(String method, String gateway) {
        String bid = UUID.randomUUID().toString();
        String tid = UUID.randomUUID().toString();
        return new CommonFieldsVo(bid, tid, method, gateway);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CommonFieldsVo that = (CommonFieldsVo) o;
        return Objects.equals(tid, that.tid) && Objects.equals(bid, that.bid) && Objects.equals(method, that.method) && Objects.equals(gateway, that.gateway);
    }

    @Override
    public int hashCode() {
        return Objects.hash(tid, bid, method);
    }
}
