package p.studio.compiler.dtos;

import com.fasterxml.jackson.annotation.*;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public record PrometeuManifestDTO(
        String name,
        String version,
        String language,
        String stdlib,
        List<DependencyDeclaration> dependencies) {

    @JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
    @JsonSubTypes({
            @JsonSubTypes.Type(value = DependencyDeclaration.Local.class),
            @JsonSubTypes.Type(value = DependencyDeclaration.Registry.class)
    })
    public interface DependencyDeclaration {
        record Local(String path) implements DependencyDeclaration {
            @JsonCreator
            public Local(@JsonProperty("path") final String path) {
                this.path = path;
            }
        }

        record Registry(String name, String version) implements DependencyDeclaration {
            @JsonCreator
            public Registry(@JsonProperty("name") final String name, @JsonProperty("version") final String version) {
                this.name = name;
                this.version = version;
            }
        }
    }
}
