"""FIT file fixing module for Tymewear generated files."""

import argparse
from fit_tool.fit_file import FitFile
from fit_tool.profile.messages.record_message import RecordMessage


def main():
    """Main entry point for the fitfix CLI."""
    ap = argparse.ArgumentParser(description="Fix small issues in FIT files generated by Tymewear")
    ap.add_argument("input_fit", help="Input FIT file path")
    ap.add_argument("output_fit", help="Output FIT file path")
    args = ap.parse_args()

    fit = FitFile.from_file(args.input_fit)

    for record in fit.records:
        if isinstance(record.message, RecordMessage):
            record.message.power = record.message.developer_fields[16].get_value()
            record.message.cadence = min(record.message.cadence * 2, 254)

    fit.crc = None
    fit.to_file(args.output_fit)


if __name__ == "__main__":
    main()