unit WsMessages;

// WebSocket push message types.
// Each constant is the value of RequestId that identifies the message kind.
// Server builds and broadcasts; client dispatches on RequestId.

interface

uses
  BaseRequest, Pkg.Json.DTO, REST.Json.Types;

{$M+}

const
  WS_MSG_BADGE_COUNTS   = 'BADGE_COUNTS';
  WS_MSG_UNIT_MAP       = 'UNIT_MAP';
  WS_MSG_COMPLAINT_MAP  = 'COMPLAINT_MAP';
  WS_MSG_UNIT_LIST      = 'UNIT_LIST';
  WS_MSG_COMPLAINT_LIST = 'COMPLAINT_LIST';

type
  // Simple typed DTO — serialized directly via AsJson for broadcast.
  TWsBadgeCountsMessage = class(TRequest)
  private
    FBadgeComplaints: Integer;
    FBadgeUnits: Integer;
  published
    property BadgeComplaints: Integer read FBadgeComplaints write FBadgeComplaints;
    property BadgeUnits: Integer read FBadgeUnits write FBadgeUnits;
  public
    constructor Create;
  end;

  // Array-payload messages: server adds RequestId to the existing TJSONObject
  // produced by the DB query methods, then broadcasts as a plain JSON string.
  // These classes exist for requestId-based type identification and future
  // client→server use (cast a received TRequest to the appropriate type).
  TWsUnitMapMessage     = class(TRequest) public constructor Create; end;
  TWsComplaintMapMessage = class(TRequest) public constructor Create; end;
  TWsUnitListMessage    = class(TRequest) public constructor Create; end;
  TWsComplaintListMessage = class(TRequest) public constructor Create; end;

implementation

constructor TWsBadgeCountsMessage.Create;
begin
  inherited;
  RequestId := WS_MSG_BADGE_COUNTS;
end;

constructor TWsUnitMapMessage.Create;
begin
  inherited;
  RequestId := WS_MSG_UNIT_MAP;
end;

constructor TWsComplaintMapMessage.Create;
begin
  inherited;
  RequestId := WS_MSG_COMPLAINT_MAP;
end;

constructor TWsUnitListMessage.Create;
begin
  inherited;
  RequestId := WS_MSG_UNIT_LIST;
end;

constructor TWsComplaintListMessage.Create;
begin
  inherited;
  RequestId := WS_MSG_COMPLAINT_LIST;
end;

end.
