package p.studio.compiler.messages;

import p.studio.compiler.models.BuildStack;
import p.studio.compiler.models.SourceKind;
import p.studio.compiler.source.identifiers.ProjectId;
import p.studio.compiler.source.tables.FileTableReader;
import p.studio.compiler.source.tables.NameTable;
import p.studio.compiler.source.tables.ProjectTableReader;

public class FrontendPhaseContext {
    public final ProjectTableReader projectTable;
    public final FileTableReader fileTable;
    public final BuildStack stack;
    private final NameTable nameTable;
    private final int stdlibVersion;
    private final HostAdmissionContext hostAdmissionContext;
    private final FESurfaceContext feSurfaceContext;

    public FrontendPhaseContext(
            final ProjectTableReader projectTable,
            final FileTableReader fileTable,
            final BuildStack stack) {
        this(projectTable, fileTable, stack, 1, HostAdmissionContext.permissiveDefault(), FESurfaceContext.empty());
    }

    public FrontendPhaseContext(
            final ProjectTableReader projectTable,
            final FileTableReader fileTable,
            final BuildStack stack,
            final int stdlibVersion) {
        this(projectTable, fileTable, stack, stdlibVersion, HostAdmissionContext.permissiveDefault(), FESurfaceContext.empty());
    }

    public FrontendPhaseContext(
            final ProjectTableReader projectTable,
            final FileTableReader fileTable,
            final BuildStack stack,
            final int stdlibVersion,
            final HostAdmissionContext hostAdmissionContext) {
        this(projectTable, fileTable, stack, stdlibVersion, hostAdmissionContext, FESurfaceContext.empty());
    }

    public FrontendPhaseContext(
            final ProjectTableReader projectTable,
            final FileTableReader fileTable,
            final BuildStack stack,
            final int stdlibVersion,
            final HostAdmissionContext hostAdmissionContext,
            final FESurfaceContext feSurfaceContext) {
        this.projectTable = projectTable;
        this.fileTable = fileTable;
        this.stack = stack;
        this.nameTable = new NameTable();
        this.stdlibVersion = stdlibVersion;
        this.hostAdmissionContext = hostAdmissionContext == null
                ? HostAdmissionContext.permissiveDefault()
                : hostAdmissionContext;
        this.feSurfaceContext = feSurfaceContext == null
                ? FESurfaceContext.empty()
                : feSurfaceContext;
    }

    public SourceKind sourceKind(final ProjectId projectId) {
        return projectTable.sourceKind(projectId);
    }

    public int stdlibVersion() {
        return stdlibVersion;
    }

    public HostAdmissionContext hostAdmissionContext() {
        return hostAdmissionContext;
    }

    public NameTable nameTable() {
        return nameTable;
    }

    public FESurfaceContext feSurfaceContext() {
        return feSurfaceContext;
    }
}
