package leigh.esp.sdk.service.schema;

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 microSvcCfg = ElementElementDAO.create();
        SchemaElementDAO.getElements(schema).add(microSvcCfg);
        ElementElementDAO.setApiName(microSvcCfg, "leigh.esp.sdk.service.v1.MicroServiceCfg");

        ElementElementDAO.getFields(microSvcCfg).add(FieldUtil.createNotNull("kabeUrl", "Kabe URL"));
        ElementElementDAO.getFields(microSvcCfg).add(FieldUtil.createNotNull("srcUri", "Source URI"));

        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-esp-sdk-service/src/main/java"));
        gen.generateJava("leigh.esp.sdk.service.schema.v1", schema);

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