package leigh.m3.sdk;

import leigh.eo.EO;
import leigh.eo.schema.DAOGenerator;
import leigh.eo.schema.dao.ElementElementDAO;
import leigh.eo.schema.dao.FieldUtil;
import leigh.eo.schema.dao.SchemaElementDAO;
import leigh.eo.schema.dao.SchemaUtil;
import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;
import leigh.mecha.util.UniversalJob;

import java.io.File;
import java.io.FileNotFoundException;

public class SchemaGeneratorApp {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(SchemaGeneratorApp.class);

    public static EO generate() {
        final EO schema = SchemaUtil.create(SchemaUtil.API_KEY);

        final EO currentPlaying = ElementElementDAO.create();
        SchemaElementDAO.getElements(schema).add(currentPlaying);
        ElementElementDAO.setApiName(currentPlaying, "leigh.esp.sdk.v1.CurrentPlaying");
        ElementElementDAO.getFields(currentPlaying).add(FieldUtil.createNotNull("title", "Song Title"));
        ElementElementDAO.getFields(currentPlaying).add(FieldUtil.createNotNull("album", "Artist"));
        ElementElementDAO.getFields(currentPlaying).add(FieldUtil.createNotNull("artist", "Album"));

        return schema;
    }

    public static void main(final String... args) throws FileNotFoundException {
        UniversalJob.banner(logger, "Apotheosis mk3", "2014 Alex Leigh");
        final EO schema = generate();
        final DAOGenerator gen = new DAOGenerator(new File("leigh-m3-sdk/src/main/java"));
        gen.generateJava("leigh.m3.sdk.v1.schema", schema);

        logger.info("Generated schema: {}", schema);
    }
}
