package io.synor.compute;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Information about an available model.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class ModelInfo {
    @JsonProperty("id")
    private String id;

    @JsonProperty("name")
    private String name;

    @JsonProperty("description")
    private String description;

    @JsonProperty("category")
    private String category;

    @JsonProperty("parameters")
    private Long parameters;

    @JsonProperty("context_length")
    private Integer contextLength;

    @JsonProperty("format")
    private String format;

    @JsonProperty("recommended_processor")
    private String recommendedProcessor;

    @JsonProperty("license")
    private String license;

    @JsonProperty("cid")
    private String cid;

    public ModelInfo() {}

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getCategory() {
        return category;
    }

    public ModelCategory getCategoryEnum() {
        return ModelCategory.fromValue(category);
    }

    public Long getParameters() {
        return parameters;
    }

    public Integer getContextLength() {
        return contextLength;
    }

    public String getFormat() {
        return format;
    }

    public String getRecommendedProcessor() {
        return recommendedProcessor;
    }

    public ProcessorType getRecommendedProcessorEnum() {
        return ProcessorType.fromValue(recommendedProcessor);
    }

    public String getLicense() {
        return license;
    }

    public String getCid() {
        return cid;
    }

    /**
     * Get formatted parameter count (e.g., "70B", "8B", "405M").
     */
    public String getFormattedParameters() {
        if (parameters == null) return "Unknown";
        if (parameters >= 1_000_000_000L) {
            return String.format("%.0fB", parameters / 1_000_000_000.0);
        } else if (parameters >= 1_000_000L) {
            return String.format("%.0fM", parameters / 1_000_000.0);
        } else if (parameters >= 1_000L) {
            return String.format("%.0fK", parameters / 1_000.0);
        }
        return parameters.toString();
    }

    @Override
    public String toString() {
        return "ModelInfo{" +
               "id='" + id + '\'' +
               ", name='" + name + '\'' +
               ", parameters=" + getFormattedParameters() +
               ", category='" + category + '\'' +
               '}';
    }
}
