#!/usr/bin/env python

"""
Generate final datasets for the project
"""
from pathlib import Path
import argparse
import logging
import logging.config
import pandas as pd

from song_lyrics.parse import json_glove
from song_lyrics.transform import bows2embeddings
from song_lyrics.util import load_logging_config_file


def main():
    logger = logging.getLogger(__name__)
    logging.basicConfig(level=logging.INFO)

    # use docstring at the top as description for the script
    parser = argparse.ArgumentParser(description=__doc__)

    parser.add_argument('path_to_data', type=str,
                        help='Path to songs data (bag of words or embeddings)')
    parser.add_argument('path_to_metadata', type=str,
                        help='Path to file with metadata')
    parser.add_argument('path_to_output', type=str,
                        help='Path to output file')

    args = parser.parse_args()
    path_to_data = args.path_to_data
    path_to_metadata = args.path_to_metadata

    mxm = pd.read_feather(path_to_data)
    metadata = pd.read_feather(path_to_metadata)

    metadata.rename(columns={c: c+'_' for c in metadata.columns
                             if c != 'track_id'}, inplace=True)

    df = metadata.merge(mxm, how='right', on='track_id')
    df.rename(columns={'track_id': 'track_id_'}, inplace=True)

    logger.info('Saving file in {}'.format(args.path_to_output))
    df.to_feather(args.path_to_output)


if __name__ == "__main__":
    main()
