package com.social.media.infrastructure.persistence.entity;

import jakarta.persistence.*;
import java.time.LocalDateTime;

/**
 * JPA Entity for SocialNetwork aggregate
 */
@Entity
@Table(name = "social_networks")
public class SocialNetworkEntity {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    
    @Column(name = "name", nullable = false, length = 100)
    private String name;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "type", nullable = false, columnDefinition = "core_business.social_platform")
    private SocialNetworkTypeEntity type;
    
    @Column(name = "base_url", nullable = false, length = 500)
    private String baseUrl;
    
    @Column(name = "api_url", length = 500)
    private String apiUrl;
    
    @Column(name = "logo_url", length = 500)
    private String logoUrl;
    
    @Column(name = "description", length = 1000)
    private String description;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, columnDefinition = "core_business.connection_status")
    private SocialNetworkStatusEntity status;
    
    @Column(name = "supports_scheduling", nullable = false)
    private Boolean supportsScheduling;
    
    @Column(name = "supports_analytics", nullable = false)
    private Boolean supportsAnalytics;
    
    @Column(name = "supports_hashtags", nullable = false)
    private Boolean supportsHashtags;
    
    @Column(name = "max_post_length")
    private Integer maxPostLength;
    
    @Column(name = "max_hashtags")
    private Integer maxHashtags;
    
    @Column(name = "supports_images", nullable = false)
    private Boolean supportsImages;
    
    @Column(name = "supports_videos", nullable = false)
    private Boolean supportsVideos;
    
    @Column(name = "max_image_size_mb")
    private Integer maxImageSizeMb;
    
    @Column(name = "max_video_size_mb")
    private Integer maxVideoSizeMb;
    
    // API Configuration fields
    @Column(name = "oauth_client_id", length = 500)
    private String oauthClientId;
    
    @Column(name = "oauth_client_secret", length = 500)
    private String oauthClientSecret;
    
    @Column(name = "oauth_redirect_url", length = 500)
    private String oauthRedirectUrl;
    
    @Column(name = "oauth_scope", length = 500)
    private String oauthScope;
    
    @Column(name = "webhook_url", length = 500)
    private String webhookUrl;
    
    // Audit fields
    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt;
    
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
    
    @Version
    @Column(name = "version")
    private Long version;
    
    // Constructors
    public SocialNetworkEntity() {}
    
    public SocialNetworkEntity(Long id, String name, SocialNetworkTypeEntity type, String baseUrl,
                              String apiUrl, String logoUrl, String description, SocialNetworkStatusEntity status,
                              Boolean supportsScheduling, Boolean supportsAnalytics, Boolean supportsHashtags,
                              Integer maxPostLength, Integer maxHashtags, Boolean supportsImages,
                              Boolean supportsVideos, Integer maxImageSizeMb, Integer maxVideoSizeMb,
                              String oauthClientId, String oauthClientSecret, String oauthRedirectUrl,
                              String oauthScope, String webhookUrl, LocalDateTime createdAt,
                              LocalDateTime updatedAt, Long version) {
        this.id = id;
        this.name = name;
        this.type = type;
        this.baseUrl = baseUrl;
        this.apiUrl = apiUrl;
        this.logoUrl = logoUrl;
        this.description = description;
        this.status = status;
        this.supportsScheduling = supportsScheduling;
        this.supportsAnalytics = supportsAnalytics;
        this.supportsHashtags = supportsHashtags;
        this.maxPostLength = maxPostLength;
        this.maxHashtags = maxHashtags;
        this.supportsImages = supportsImages;
        this.supportsVideos = supportsVideos;
        this.maxImageSizeMb = maxImageSizeMb;
        this.maxVideoSizeMb = maxVideoSizeMb;
        this.oauthClientId = oauthClientId;
        this.oauthClientSecret = oauthClientSecret;
        this.oauthRedirectUrl = oauthRedirectUrl;
        this.oauthScope = oauthScope;
        this.webhookUrl = webhookUrl;
        this.createdAt = createdAt;
        this.updatedAt = updatedAt;
        this.version = version;
    }
    
    // Getters and Setters
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    
    public SocialNetworkTypeEntity getType() { return type; }
    public void setType(SocialNetworkTypeEntity type) { this.type = type; }
    
    public String getBaseUrl() { return baseUrl; }
    public void setBaseUrl(String baseUrl) { this.baseUrl = baseUrl; }
    
    public String getApiUrl() { return apiUrl; }
    public void setApiUrl(String apiUrl) { this.apiUrl = apiUrl; }
    
    public String getLogoUrl() { return logoUrl; }
    public void setLogoUrl(String logoUrl) { this.logoUrl = logoUrl; }
    
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    
    public SocialNetworkStatusEntity getStatus() { return status; }
    public void setStatus(SocialNetworkStatusEntity status) { this.status = status; }
    
    public Boolean getSupportsScheduling() { return supportsScheduling; }
    public void setSupportsScheduling(Boolean supportsScheduling) { this.supportsScheduling = supportsScheduling; }
    
    public Boolean getSupportsAnalytics() { return supportsAnalytics; }
    public void setSupportsAnalytics(Boolean supportsAnalytics) { this.supportsAnalytics = supportsAnalytics; }
    
    public Boolean getSupportsHashtags() { return supportsHashtags; }
    public void setSupportsHashtags(Boolean supportsHashtags) { this.supportsHashtags = supportsHashtags; }
    
    public Integer getMaxPostLength() { return maxPostLength; }
    public void setMaxPostLength(Integer maxPostLength) { this.maxPostLength = maxPostLength; }
    
    public Integer getMaxHashtags() { return maxHashtags; }
    public void setMaxHashtags(Integer maxHashtags) { this.maxHashtags = maxHashtags; }
    
    public Boolean getSupportsImages() { return supportsImages; }
    public void setSupportsImages(Boolean supportsImages) { this.supportsImages = supportsImages; }
    
    public Boolean getSupportsVideos() { return supportsVideos; }
    public void setSupportsVideos(Boolean supportsVideos) { this.supportsVideos = supportsVideos; }
    
    public Integer getMaxImageSizeMb() { return maxImageSizeMb; }
    public void setMaxImageSizeMb(Integer maxImageSizeMb) { this.maxImageSizeMb = maxImageSizeMb; }
    
    public Integer getMaxVideoSizeMb() { return maxVideoSizeMb; }
    public void setMaxVideoSizeMb(Integer maxVideoSizeMb) { this.maxVideoSizeMb = maxVideoSizeMb; }
    
    public String getOauthClientId() { return oauthClientId; }
    public void setOauthClientId(String oauthClientId) { this.oauthClientId = oauthClientId; }
    
    public String getOauthClientSecret() { return oauthClientSecret; }
    public void setOauthClientSecret(String oauthClientSecret) { this.oauthClientSecret = oauthClientSecret; }
    
    public String getOauthRedirectUrl() { return oauthRedirectUrl; }
    public void setOauthRedirectUrl(String oauthRedirectUrl) { this.oauthRedirectUrl = oauthRedirectUrl; }
    
    public String getOauthScope() { return oauthScope; }
    public void setOauthScope(String oauthScope) { this.oauthScope = oauthScope; }
    
    public String getWebhookUrl() { return webhookUrl; }
    public void setWebhookUrl(String webhookUrl) { this.webhookUrl = webhookUrl; }
    
    public LocalDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
    
    public LocalDateTime getUpdatedAt() { return updatedAt; }
    public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
    
    public Long getVersion() { return version; }
    public void setVersion(Long version) { this.version = version; }
    
    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
    }
    
    @PreUpdate
    protected void onUpdate() {
        updatedAt = LocalDateTime.now();
    }
}
