package com.social.media.domain.company.valueobjects;

import com.social.media.domain.shared.valueobjects.EntityId;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.UUID;

/**
 * Type-safe identifier for Company entities.
 * 
 * Provides compile-time type safety preventing accidental assignment
 * of other entity IDs to Company references.
 * 
 * @author Social Media Manager Team
 * @since 2.0.0
 */
public final class CompanyId extends EntityId {
    
    /**
     * Protected constructor for JPA
     */
    protected CompanyId() {
        super();
    }
    
    /**
     * Constructor with UUID value
     */
    private CompanyId(UUID value) {
        super(value);
    }
    
    /**
     * Constructor with string value for JSON deserialization
     */
    @JsonCreator
    private CompanyId(String value) {
        super(value);
    }
    
    /**
     * Generate a new random CompanyId
     */
    public static CompanyId newCompanyId() {
        return new CompanyId(UUID.randomUUID());
    }
    
    /**
     * Create CompanyId from UUID
     */
    public static CompanyId of(UUID value) {
        return new CompanyId(value);
    }
    
    /**
     * Create CompanyId from String
     */
    public static CompanyId of(String value) {
        return new CompanyId(value);
    }
    
    /**
     * Create CompanyId from Long
     */
    public static CompanyId of(Long value) {
        return new CompanyId(value.toString());
    }
    
    /**
     * Get the value as Long (if possible)
     */
    public Long getValueAsLong() {
        try {
            return Long.valueOf(getStringValue());
        } catch (NumberFormatException e) {
            // If not a valid Long, return hash code
            return (long) getStringValue().hashCode();
        }
    }
    
    @JsonValue
    @Override
    public String toString() {
        return getStringValue();
    }
}
