package com.petshop.backend.dto.chat;

import com.petshop.backend.entity.Message;

import java.time.LocalDateTime;

public class MessageResponse {
    private Long id;
    private Long conversationId;
    private Long senderId;
    private String senderRole;
    private String senderDisplayName;
    private String senderAvatarUrl;
    private String content;
    private LocalDateTime timestamp;
    private Boolean isRead;
    private String attachmentUrl;
    private String attachmentName;
    private String attachmentMimeType;
    private Long attachmentSizeBytes;

    public MessageResponse() {
    }

    public MessageResponse(Long id, Long conversationId, Long senderId, String senderAvatarUrl, String content, LocalDateTime timestamp, Boolean isRead) {
        this.id = id;
        this.conversationId = conversationId;
        this.senderId = senderId;
        this.senderAvatarUrl = senderAvatarUrl;
        this.content = content;
        this.timestamp = timestamp;
        this.isRead = isRead;
    }

    public static MessageResponse fromEntity(Message message) {
        MessageResponse response = new MessageResponse();
        response.setId(message.getId());
        response.setConversationId(message.getConversationId());
        response.setSenderId(message.getSenderId());
        response.setContent(message.getContent());
        response.setTimestamp(message.getTimestamp());
        response.setIsRead(message.getIsRead());
        

        if (message.getAttachmentUrl() != null) {
            response.setAttachmentUrl("/api/v1/chat/messages/" + message.getId() + "/attachment");
        }

        response.setAttachmentName(message.getAttachmentName());
        response.setAttachmentMimeType(message.getAttachmentMimeType());
        response.setAttachmentSizeBytes(message.getAttachmentSizeBytes());
        return response;
    }

    public String getSenderAvatarUrl() {
        return senderAvatarUrl;
    }

    public void setSenderAvatarUrl(String senderAvatarUrl) {
        this.senderAvatarUrl = senderAvatarUrl;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getConversationId() {
        return conversationId;
    }

    public void setConversationId(Long conversationId) {
        this.conversationId = conversationId;
    }

    public Long getSenderId() {
        return senderId;
    }

    public void setSenderId(Long senderId) {
        this.senderId = senderId;
    }

    public String getSenderRole() {
        return senderRole;
    }

    public void setSenderRole(String senderRole) {
        this.senderRole = senderRole;
    }

    public String getSenderDisplayName() {
        return senderDisplayName;
    }

    public void setSenderDisplayName(String senderDisplayName) {
        this.senderDisplayName = senderDisplayName;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public LocalDateTime getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(LocalDateTime timestamp) {
        this.timestamp = timestamp;
    }

    public Boolean getIsRead() {
        return isRead;
    }

    public void setIsRead(Boolean isRead) {
        this.isRead = isRead;
    }

    public String getAttachmentUrl() {
        return attachmentUrl;
    }

    public void setAttachmentUrl(String attachmentUrl) {
        this.attachmentUrl = attachmentUrl;
    }

    public String getAttachmentName() {
        return attachmentName;
    }

    public void setAttachmentName(String attachmentName) {
        this.attachmentName = attachmentName;
    }

    public String getAttachmentMimeType() {
        return attachmentMimeType;
    }

    public void setAttachmentMimeType(String attachmentMimeType) {
        this.attachmentMimeType = attachmentMimeType;
    }

    public Long getAttachmentSizeBytes() {
        return attachmentSizeBytes;
    }

    public void setAttachmentSizeBytes(Long attachmentSizeBytes) {
        this.attachmentSizeBytes = attachmentSizeBytes;
    }
}
