/*
 * Copyright (c) 京北方信息技术股份有限公司 Corporation 2020 . All rights reserved.
 *
 */
package net.northking.cctp.maven.plugin;

import net.northking.cctp.maven.gen.CCTPGenerator;
import net.northking.cctp.maven.analyse.entity.TableRef;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

/**
 * Http接口
 *
 * @author : xiusong.xie
 * @version : 1.0
 */
@Mojo(name = "http-api", threadSafe = true)
public class HttpApiMojo extends AbsDatabaseLoadMojo
{
  /**
   * Maven工程对象
   **/
  @Parameter(defaultValue = "${project}", readonly = true, required = true)
  private MavenProject project;


  /**
   * basePackage
   */
  @Parameter(required = true)
  private String basePackage;

  /**
   * 生成数据库表的实体对象
   *
   * @throws MojoExecutionException 异常
   * @throws MojoFailureException   异常
   */
  public final void execute() throws MojoExecutionException, MojoFailureException
  {
    CCTPGenerator generator = new CCTPGenerator(project.getBasedir(), basePackage);
    for (TableRef tableRef : loadTables())
    {
      if (tableNames != null)
      {
        for (String tableName : tableNames)
        {
          if (tableRef.getTableName().equalsIgnoreCase(tableName))
          {
            generator.genHttpApi(tableRef);
            break;
          }
        }
      } else
      {
        generator.genHttpApi(tableRef);
      }
    }

  }
}
