"""Adds RAS Items to a STAC collection.

TODO: Refactor, this script was written in one setting and needs to be revised significantly.
"""

# import argparse
# import logging
# import os
# from typing import List

# import pystac
# from dotenv import load_dotenv

# from ripple1d.utils.s3_utils import init_s3_resources, list_keys
# from ripple1d.utils.stac_utils import (
#     create_collection,
#     key_to_uri,
#     upsert_collection,
#     upsert_item,
# )

# load_dotenv()
# # STAC API URL
# API_URL = os.getenv("STAC_API_URL")


# def main(
#     new_collection_items: List[pystac.Item],
#     collection_id: str,
#     description: str,
#     title: str,
# ):
#     """Given a list of items autogenerated using MCAT-RAS and ras-stac, this function creates a new collection in the STAC_API and adds the items to the collection."""
#     collection = create_collection(new_collection_items, collection_id, description, title)
#     r = upsert_collection(API_URL, collection)

#     for item in new_collection_items:
#         r = upsert_item(API_URL, collection_id, item)
#         logging.info(f"Adding {item.id} to {collection_id} collection")


# if __name__ == "__main__":

#     _, s3_client, _ = init_s3_resources()

#     parser = argparse.ArgumentParser(description="")
#     parser.add_argument("--collection_id", type=str, required=True, help="Collection ID")
#     parser.add_argument("--bucket_name", type=str, required=True, help="Bucket name")
#     parser.add_argument("--bucket_prefix", type=str, required=True, help="Bucket prefix")
#     parser.add_argument("--description", type=str, required=True, help="Description")
#     parser.add_argument("--title", type=str, required=True, help="Title")

#     args = parser.parse_args()

#     _, s3_client, _ = init_s3_resources()

#     collection_id = args.collection_id

#     bucket_name = args.bucket_name
#     bucket_prefix = args.bucket_prefix
#     title = args.title
#     description = args.description

#     # Read json files created using ras-stac and stored on s3
#     json_keys = list_keys(s3_client, bucket_name, bucket_prefix, "json")

#     new_collection_items = []

#     for jkey in json_keys[10:15]:
#         item = pystac.Item.from_file(key_to_uri(jkey, bucket_name))
#         new_collection_items.append(item)

#     main(new_collection_items, collection_id, description, title)
