from __future__ import annotations

import argparse

from rdkit import Chem

from macro_lactone_toolkit.splicing import (
    activate_fragment,
    prepare_macrolactone_scaffold,
    splice_molecule,
)


def main() -> None:
    parser = argparse.ArgumentParser(description="Splice a fragment onto a prepared macrolactone scaffold.")
    parser.add_argument("--scaffold-smiles", required=True)
    parser.add_argument("--fragment-smiles", required=True)
    parser.add_argument("--position", required=True, type=int)
    parser.add_argument("--ring-size", type=int, default=None)
    parser.add_argument("--strategy", default="smart")
    args = parser.parse_args()

    scaffold, _ = prepare_macrolactone_scaffold(
        args.scaffold_smiles,
        positions=[args.position],
        ring_size=args.ring_size,
    )
    fragment = activate_fragment(args.fragment_smiles, strategy=args.strategy)
    product = splice_molecule(scaffold, fragment, position=args.position)
    print(Chem.MolToSmiles(product, isomericSmiles=True))


if __name__ == "__main__":
    main()
