// Description of the database schema.
// static_tables: Tables that should exist by default. Each table is represented as a 3-member tuple in a vector
//				 wxString : Database name
//				 char *: The column types as a char array in cisTEM convention
//               vector<wxString>: The column names
// dynamic_tables: Tables that are created for each result. Each table is represented as a 3-member tuple in a vector
//				 wxString : Database name prefix. Existing tables will have the result number as a suffix.
//				 char *: The column types as a char array in cisTEM convention
//               vector<wxString>: The column names
namespace database_schema {
using TableData = std::tuple<wxString, char*, std::vector<wxString>>;

enum {
    TABLE_NAME,
    TABLE_TYPES,
    TABLE_COLUMNS
};

std::vector<TableData> static_tables{
        {"MASTER_SETTINGS", "pttiriti", {"NUMBER", "PROJECT_DIRECTORY", "PROJECT_NAME", "CURRENT_VERSION", "TOTAL_CPU_HOURS", "TOTAL_JOBS_RUN", "CISTEM_VERSION_TEXT", "CURRENT_WORKFLOW"}},
        {"PROCESS_LOCK", "plt", {"NUMBER", "ACTIVE_PROCESS", "ACTIVE_HOST"}},
        {"PARTICLE_PICKING_LIST", "piiiirrrriiiii", {"PICKING_ID", "DATETIME_OF_RUN", "PICKING_JOB_ID", "PARENT_IMAGE_ASSET_ID", "PICKING_ALGORITHM", "CHARACTERISTIC_RADIUS", "MAXIMUM_RADIUS", "THRESHOLD_PEAK_HEIGHT", "HIGHEST_RESOLUTION_USED_IN_PICKING", "MIN_DIST_FROM_EDGES", "AVOID_HIGH_VARIANCE", "AVOID_HIGH_LOW_MEAN", "NUM_BACKGROUND_BOXES", "MANUAL_EDIT"}},
        {"RUNNING_JOBS", "pti", {"JOB_NUMBER", "JOB_CODE", "MANAGER_IP_ADDRESS"}},
        {"RUN_PROFILES", "ptttti", {"RUN_PROFILE_ID", "PROFILE_NAME", "MANAGER_RUN_COMMAND", "GUI_ADDRESS", "CONTROLLER_ADDRESS", "COMMANDS_ID"}},
        {"MOVIE_ASSETS", "pttiiiirrrrttrirrriii", {"MOVIE_ASSET_ID", "NAME", "FILENAME", "POSITION_IN_STACK", "X_SIZE", "Y_SIZE", "NUMBER_OF_FRAMES", "VOLTAGE", "PIXEL_SIZE", "DOSE_PER_FRAME", "SPHERICAL_ABERRATION", "GAIN_FILENAME", "DARK_FILENAME", "OUTPUT_BINNING_FACTOR", "CORRECT_MAG_DISTORTION", "MAG_DISTORTION_ANGLE", "MAG_DISTORTION_MAJOR_SCALE", "MAG_DISTORTION_MINOR_SCALE", "PROTEIN_IS_WHITE", "EER_SUPER_RES_FACTOR", "EER_FRAMES_PER_IMAGE"}},
        {"IMAGE_ASSETS", "pttiiiiiirrri", {"IMAGE_ASSET_ID", "NAME", "FILENAME", "POSITION_IN_STACK", "PARENT_MOVIE_ID", "ALIGNMENT_ID", "CTF_ESTIMATION_ID", "X_SIZE", "Y_SIZE", "PIXEL_SIZE", "VOLTAGE", "SPHERICAL_ABERRATION", "PROTEIN_IS_WHITE"}},
        {"MOVIE_GROUP_LIST", "pti", {"GROUP_ID", "GROUP_NAME", "LIST_ID"}},
        {"MOVIE_ALIGNMENT_LIST", "piiitrrrrrriiriiiiiiii", {"ALIGNMENT_ID", "DATETIME_OF_RUN", "ALIGNMENT_JOB_ID", "MOVIE_ASSET_ID", "OUTPUT_FILE", "VOLTAGE", "PIXEL_SIZE", "EXPOSURE_PER_FRAME", "PRE_EXPOSURE_AMOUNT", "MIN_SHIFT", "MAX_SHIFT", "SHOULD_DOSE_FILTER", "SHOULD_RESTORE_POWER", "TERMINATION_THRESHOLD", "MAX_ITERATIONS", "BFACTOR", "SHOULD_MASK_CENTRAL_CROSS", "HORIZONTAL_MASK", "VERTICAL_MASK", "SHOULD_INCLUDE_ALL_FRAMES_IN_SUM", "FIRST_FRAME_TO_SUM", "LAST_FRAME_TO_SUM"}},
        {"IMAGE_GROUP_LIST", "pti", {"GROUP_ID", "GROUP_NAME", "LIST_ID"}},
        {"PARTICLE_PICKING_LIST", "piiiirrrriiiii", {"PICKING_ID", "DATETIME_OF_RUN", "PICKING_JOB_ID", "PARENT_IMAGE_ASSET_ID", "PICKING_ALGORITHM", "CHARACTERISTIC_RADIUS", "MAXIMUM_RADIUS", "THRESHOLD_PEAK_HEIGHT", "HIGHEST_RESOLUTION_USED_IN_PICKING", "MIN_DIST_FROM_EDGES", "AVOID_HIGH_VARIANCE", "AVOID_HIGH_LOW_MEAN", "NUM_BACKGROUND_BOXES", "MANUAL_EDIT"}},
        {"PARTICLE_POSITION_ASSETS", "piiirrrirrr", {"PARTICLE_POSITION_ASSET_ID", "PARENT_IMAGE_ASSET_ID", "PICKING_ID", "PICK_JOB_ID", "X_POSITION", "Y_POSITION", "PEAK_HEIGHT", "TEMPLATE_ASSET_ID", "TEMPLATE_PSI", "TEMPLATE_THETA", "TEMPLATE_PHI"}},
        {"PARTICLE_POSITION_GROUP_LIST", "pti", {"GROUP_ID", "GROUP_NAME", "LIST_ID"}},
        {"ESTIMATED_CTF_PARAMETERS", "piiiirrrrirrrrririrrrrrrrrrrtiirrr", {"CTF_ESTIMATION_ID", "CTF_ESTIMATION_JOB_ID", "DATETIME_OF_RUN", "IMAGE_ASSET_ID", "ESTIMATED_ON_MOVIE_FRAMES", "VOLTAGE", "SPHERICAL_ABERRATION", "PIXEL_SIZE", "AMPLITUDE_CONTRAST", "BOX_SIZE", "MIN_RESOLUTION", "MAX_RESOLUTION", "MIN_DEFOCUS", "MAX_DEFOCUS", "DEFOCUS_STEP", "RESTRAIN_ASTIGMATISM", "TOLERATED_ASTIGMATISM", "FIND_ADDITIONAL_PHASE_SHIFT", "MIN_PHASE_SHIFT", "MAX_PHASE_SHIFT", "PHASE_SHIFT_STEP", "DEFOCUS1", "DEFOCUS2", "DEFOCUS_ANGLE", "ADDITIONAL_PHASE_SHIFT", "SCORE", "DETECTED_RING_RESOLUTION", "DETECTED_ALIAS_RESOLUTION", "OUTPUT_DIAGNOSTIC_FILE", "NUMBER_OF_FRAMES_AVERAGED", "LARGE_ASTIGMATISM_EXPECTED", "ICINESS", "TILT_ANGLE", "TILT_AXIS"}},
        {"VOLUME_ASSETS", "pttiriiitt", {"VOLUME_ASSET_ID", "NAME", "FILENAME", "RECONSTRUCTION_JOB_ID", "PIXEL_SIZE", "X_SIZE", "Y_SIZE", "Z_SIZE", "HALF_MAP1_FILENAME", "HALF_MAP2_FILENAME"}},
        {"VOLUME_GROUP_LIST", "pti", {"GROUP_ID", "GROUP_NAME", "LIST_ID"}},
#ifdef EXPERIMENTAL
        {"ATOMIC_COORDINATES_ASSETS", "pttiiiitrrr", {"ATOMIC_COORDINATES_ASSET_ID", "NAME", "FILENAME", "SIMULATION_3D_JOB_ID", "X_SIZE", "Y_SIZE", "Z_SIZE", "PDB_ID", "PDB_AVG_BFACTOR", "PDB_STD_BFACTOR", "EFFECTIVE_WEIGHT"}},
        {"ATOMIC_COORDINATES_GROUP_LIST", "pti", {"GROUP_ID", "GROUP_NAME", "LIST_ID"}},
// TODO: I'm not sure if the following sections that are related to refinement will also be needed for AtomicCoordinates objects, though I may be given we do refinement....just not refinement packages.
#endif
        {"REFINEMENT_PACKAGE_ASSETS", "pttirtrriiii", {"REFINEMENT_PACKAGE_ASSET_ID", "NAME", "STACK_FILENAME", "STACK_BOX_SIZE", "OUTPUT_PIXEL_SIZE", "SYMMETRY", "MOLECULAR_WEIGHT", "PARTICLE_SIZE", "NUMBER_OF_CLASSES", "NUMBER_OF_REFINEMENTS", "LAST_REFINEMENT_ID", "STACK_HAS_WHITE_PROTEIN"}},
        {"REFINEMENT_LIST", "Pltillllirr", {"REFINEMENT_ID", "REFINEMENT_PACKAGE_ASSET_ID", "NAME", "RESOLUTION_STATISTICS_ARE_GENERATED", "DATETIME_OF_RUN", "STARTING_REFINEMENT_ID", "NUMBER_OF_PARTICLES", "NUMBER_OF_CLASSES", "RESOLUTION_STATISTICS_BOX_SIZE", "RESOLUTION_STATISTICS_PIXEL_SIZE", "PERCENT_USED"}},
        {"MOVIE_ASSETS_METADATA", "Plttrrrrrrrl", {"MOVIE_ASSET_METADATA_ID", "MOVIE_ASSET_ID", "METADATA_SOURCE", "CONTENT_JSON", "TILT_ANGLE", "STAGE_POSITION_X", "STAGE_POSITION_Y", "STAGE_POSITION_Z", "IMAGE_SHIFT_X", "IMAGE_SHIFT_Y", "EXPOSURE_DOSE", "ACQUISITION_TIME"}},
        {"TEMPLATE_MATCH_LIST", "Ptllilllitrrrrrrrrrrrrrrrrrrrrrrittttttttttt", {"TEMPLATE_MATCH_ID", "JOB_NAME", "DATETIME_OF_RUN", "TEMPLATE_MATCH_JOB_ID", "JOB_TYPE_CODE", "INPUT_TEMPLATE_MATCH_ID", "IMAGE_ASSET_ID", "REFERENCE_VOLUME_ASSET_ID", "IS_ACTIVE", "USED_SYMMETRY", "USED_PIXEL_SIZE", "USED_VOLTAGE", "USED_SPHERICAL_ABERRATION", "USED_AMPLITUDE_CONTRAST", "USED_DEFOCUS1", "USED_DEFOCUS2", "USED_DEFOCUS_ANGLE", "USED_PHASE_SHIFT", "LOW_RESOLUTION_LIMIT", "HIGH_RESOLUTION_LIMIT", "OUT_OF_PLANE_ANGULAR_STEP", "IN_PLANE_ANGULAR_STEP", "DEFOCUS_SEARCH_RANGE", "DEFOCUS_STEP", "PIXEL_SIZE_SEARCH_RANGE", "PIXEL_SIZE_STEP", "REFINEMENT_THRESHOLD", "USED_THRESHOLD", "REF_BOX_SIZE_IN_ANGSTROMS", "MASK_RADIUS", "MIN_PEAK_RADIUS", "XY_CHANGE_THRESHOLD", "EXCLUDE_ABOVE_XY_THRESHOLD", "MIP_OUTPUT_FILE", "SCALED_MIP_OUTPUT_FILE", "AVG_OUTPUT_FILE", "STD_OUTPUT_FILE", "PSI_OUTPUT_FILE", "THETA_OUTPUT_FILE", "PHI_OUTPUT_FILE", "DEFOCUS_OUTPUT_FILE", "PIXEL_SIZE_OUTPUT_FILE", "HISTOGRAM_OUTPUT_FILE", "PROJECTION_RESULT_OUTPUT_FILE"}},
        {"CLASSIFICATION_LIST", "Plttilllirrrrrrriir", {"CLASSIFICATION_ID", "REFINEMENT_PACKAGE_ASSET_ID", "NAME", "CLASS_AVERAGE_FILE", "REFINEMENT_WAS_IMPORTED_OR_GENERATED", "DATETIME_OF_RUN", "STARTING_CLASSIFICATION_ID", "NUMBER_OF_PARTICLES", "NUMBER_OF_CLASSES", "LOW_RESOLUTION_LIMIT", "HIGH_RESOLUTION_LIMIT", "MASK_RADIUS", "ANGULAR_SEARCH_STEP", "SEARCH_RANGE_X", "SEARCH_RANGE_Y", "SMOOTHING_FACTOR", "EXCLUDE_BLANK_EDGES", "AUTO_PERCENT_USED", "PERCENT_USED"}},
        {"CLASSIFICATION_SELECTION_LIST", "Ptlllii", {"SELECTION_ID", "SELECTION_NAME", "CREATION_DATE", "REFINEMENT_PACKAGE_ID", "CLASSIFICATION_ID", "NUMBER_OF_CLASSES", "NUMBER_OF_SELECTIONS"}},
        {"STARTUP_LIST", "Pltiirriirrrir", {"STARTUP_ID", "REFINEMENT_PACKAGE_ASSET_ID", "NAME", "NUMBER_OF_STARTS", "NUMBER_OF_CYCLES", "INITIAL_RES_LIMIT", "FINAL_RES_LIMIT", "AUTO_MASK", "AUTO_PERCENT_USED", "INITIAL_PERCENT_USED", "FINAL_PERCENT_USED", "MASK_RADIUS", "APPLY_LIKELIHOOD_BLURRING", "SMOOTHING_FACTOR"}},
        {"RECONSTRUCTION_LIST", "Plltrrrriiiiril", {"RECONSTRUCTION_ID", "REFINEMENT_PACKAGE_ID", "REFINEMENT_ID", "NAME", "INNER_MASK_RADIUS", "OUTER_MASK_RADIUS", "RESOLUTION_LIMIT", "SCORE_WEIGHT_CONVERSION", "SHOULD_ADJUST_SCORES", "SHOULD_CROP_IMAGES", "SHOULD_SAVE_HALF_MAPS", "SHOULD_LIKELIHOOD_BLUR", "SMOOTHING_FACTOR", "CLASS_NUMBER", "VOLUME_ASSET_ID"}}};

std::vector<TableData> dynamic_tables{
        {"MOVIE_ALIGNMENT_PARAMETERS_", "prr", {"FRAME_NUMBER", "X_SHIFT", "Y_SHIFT"}},
        {"ATOMIC_COORDINATES_GROUP_", "ii", {"MEMBER_NUMBER", "ATOMIC_COORDINATES_POSITION_ASSET_ID"}},
        {"IMAGE_GROUP_", "ii", {"MEMBER_NUMBER", "IMAGE_ASSET_ID"}},
        {"MOVIE_GROUP_", "ii", {"MEMBER_NUMBER", "MOVIE_ASSET_ID"}},
        {"PARTICLE_POSITION_GROUP_", "ii", {"MEMBER_NUMBER", "PARTICLE_POSITION_ASSET_ID"}},
        {"VOLUME_GROUP_", "ii", {"MEMBER_NUMBER", "VOLUME_POSITION_ASSET_ID"}},
        {"RUN_PROFILE_COMMANDS_", "ptiiiii", {"COMMANDS_NUMBER", "COMMAND_STRING", "NUMBER_OF_COPIES", "NUMBER_OF_THREADS_PER_COPY", "OVERRIDE_TOTAL_NUMBER_OF_COPIES", "OVERIDDEN_TOTAL_NUMBER_OF_COPIES", "DELAY_TIME_IN_MS"}},
        {"MOVIE_IMPORT_DEFAULTS", "prrrrititirirrriii", {"NUMBER", "VOLTAGE", "SPHERICAL_ABERRATION", "PIXEL_SIZE", "EXPOSURE_PER_FRAME", "MOVIES_ARE_GAIN_CORRECTED", "GAIN_REFERENCE_FILENAME", "MOVIES_ARE_DARK_CORRECTED", "DARK_REFERENCE_FILENAME", "RESAMPLE_MOVIES", "DESIRED_PIXEL_SIZE", "CORRECT_MAG_DISTORTION", "MAG_DISTORTION_ANGLE", "MAG_DISTORTION_MAJOR_SCALE", "MAG_DISTORTION_MINOR_SCALE", "PROTEIN_IS_WHITE", "EER_SUPER_RES_FACTOR", "EER_FRAMES_PER_IMAGE"}},
        {"IMAGE_IMPORT_DEFAULTS", "prrri", {"NUMBER", "VOLTAGE", "SPHERICAL_ABERRATION", "PIXEL_SIZE", "PROTEIN_IS_WHITE"}},
        {"REFINEMENT_PACKAGE_CONTAINED_PARTICLES_", "piirrrrrrrrrri", {"ORIGINAL_PARTICLE_POSITION_ASSET_ID", "PARENT_IMAGE_ASSET_ID", "POSITION_IN_STACK", "X_POSITION", "Y_POSITION", "PIXEL_SIZE", "DEFOCUS_1", "DEFOCUS_2", "DEFOCUS_ANGLE", "PHASE_SHIFT", "SPHERICAL_ABERRATION", "MICROSCOPE_VOLTAGE", "AMPLITUDE_CONTRAST", "ASSIGNED_SUBSET"}},
        {"STARTUP_RESULT_", "pl", {"CLASS_NUMBER", "VOLUME_ASSET_ID"}},
        {"CLASSIFICATION_SELECTION_", "pl", {"SELECTION_NUMBER", "CLASS_AVERAGE_NUMBER"}},
        {"CLASSIFICATION_RESULT_", "Prrrirrrrrrrrrrrrrr", {"POSITION_IN_STACK", "PSI", "XSHIFT", "YSHIFT", "BEST_CLASS", "SIGMA", "LOGP", "PIXEL_SIZE", "VOLTAGE", "CS", "AMPLITUDE_CONTRAST", "DEFOCUS_1", "DEFOCUS_2", "DEFOCUS_ANGLE", "PHASE_SHIFT", "BEAM_TILT_X", "BEAM_TILT_Y", "IMAGE_SHIFT_X", "IMAGE_SHIFT_Y"}},
        {"TEMPLATE_MATCH_PEAK_LIST_", "prrrrrrrr", {"PEAK_NUMBER", "X_POSITION", "Y_POSITION", "PSI", "THETA", "PHI", "DEFOCUS", "PIXEL_SIZE", "PEAK_HEIGHT"}},
        {"TEMPLATE_MATCH_PEAK_CHANGE_LIST_", "prrrrrrrrii", {"PEAK_NUMBER", "X_POSITION", "Y_POSITION", "PSI", "THETA", "PHI", "DEFOCUS", "PIXEL_SIZE", "PEAK_HEIGHT", "ORIGINAL_PEAK_NUMBER", "NEW_PEAK_NUMBER"}},
        {"REFINEMENT_RESULT_", "Prrrrrrrrrrrrrirrrrrrrri", {"POSITION_IN_STACK", "PSI", "THETA", "PHI", "XSHIFT", "YSHIFT", "DEFOCUS1", "DEFOCUS2", "DEFOCUS_ANGLE", "PHASE_SHIFT", "OCCUPANCY", "LOGP", "SIGMA", "SCORE", "IMAGE_IS_ACTIVE", "PIXEL_SIZE", "MICROSCOPE_VOLTAGE", "MICROSCOPE_CS", "AMPLITUDE_CONTRAST", "BEAM_TILT_X", "BEAM_TILT_Y", "IMAGE_SHIFT_X", "IMAGE_SHIFT_Y", "ASSIGNED_SUBSET"}},
        {"REFINEMENT_RESOLUTION_STATISTICS_", "prrrrr", {"SHELL", "RESOLUTION", "FSC", "PART_FSC", "PART_SSNR", "REC_SSNR"}},
        {"REFINEMENT_ANGULAR_DISTRIBUTION_", "pr", {"BIN_NUMBER", "NUMBER_IN_BIN"}},
        {"REFINEMENT_PACKAGE_CONTAINED_PARTICLES_", "piirrrrrrrrrri", {"ORIGINAL_PARTICLE_POSITION_ASSET_ID", "PARENT_IMAGE_ASSET_ID", "POSITION_IN_STACK", "X_POSITION", "Y_POSITION", "PIXEL_SIZE", "DEFOCUS_1", "DEFOCUS_2", "DEFOCUS_ANGLE", "PHASE_SHIFT", "SPHERICAL_ABERRATION", "MICROSCOPE_VOLTAGE", "AMPLITUDE_CONTRAST", "ASSIGNED_SUBSET"}},
        {"REFINEMENT_PACKAGE_CURRENT_REFERENCES_", "pi", {"CLASS_NUMBER", "VOLUME_ASSET_ID"}},
        {"REFINEMENT_PACKAGE_REFINEMENTS_LIST_", "pl", {"REFINEMENT_NUMBER", "REFINEMENT_ID"}},
        {"REFINEMENT_PACKAGE_CLASSIFICATIONS_LIST_", "pl", {"CLASSIFICATION_NUMBER", "CLASSIFICATION_ID"}},
        {"REFINEMENT_DETAILS_", "plrrrrrrirrrrirrrrirrrrlliiilrrir", {"CLASS_NUMBER", "REFERENCE_VOLUME_ASSET_ID", "LOW_RESOLUTION_LIMIT", "HIGH_RESOLUTION_LIMIT", "MASK_RADIUS", "SIGNED_CC_RESOLUTION_LIMIT", "GLOBAL_RESOLUTION_LIMIT", "GLOBAL_MASK_RADIUS", "NUMBER_RESULTS_TO_REFINE", "ANGULAR_SEARCH_STEP", "SEARCH_RANGE_X", "SEARCH_RANGE_Y", "CLASSIFICATION_RESOLUTION_LIMIT", "SHOULD_FOCUS_CLASSIFY", "SPHERE_X_COORD", "SPHERE_Y_COORD", "SPHERE_Z_COORD", "SPHERE_RADIUS", "SHOULD_REFINE_CTF", "DEFOCUS_SEARCH_RANGE", "DEFOCUS_SEARCH_STEP", "AVERAGE_OCCUPANCY", "ESTIMATED_RESOLUTION", "RECONSTRUCTED_VOLUME_ASSET_ID", "RECONSTRUCTION_ID", "SHOULD_AUTOMASK", "SHOULD_REFINE_INPUT_PARAMS", "SHOULD_USE_SUPPLIED_MASK", "MASK_ASSET_ID", "MASK_EDGE_WIDTH", "OUTSIDE_MASK_WEIGHT", "SHOULD_LOWPASS_OUTSIDE_MASK", "MASK_FILTER_RESOLUTION"}}};

} // namespace database_schema
