import json, requests, datetime, time
from api_auth import APICredentials, APIParams

class CSLSlicer:
    def __init__(self):
        self.host = "https://services.uplynk.com"

    def run(self):
        """
        Create a slicer.
        """
        self._create_csl_slicer()

    def _create_csl_slicer(self):
        url = "{}{}".format(self.host, "/api/v4/managed-slicer/slicers")

        ingest_point_id = 'f0a214a437024a9c85c59f6f1bd55b3e' # Replace with the desired ingest point's ID.
        region_id = 'e1d9f8f3c9a24be68177654ded5b2912'  # Replace with the desired region's ID.

        payload = {
            'slicer_name': 'Basketball Slicer', # Replace with the slicer's name.
            'slicer_id': 'basketball_slicer', # Replace with the slicer's Slicer ID.
            'ingest_point_id': ingest_point_id,
            'server_region_id': region_id,
            'default_slicer_config': False,
            'stream_type_name': "RTMP",
            'configuration': 'remote:on\ndescription:Sports\ninput:rtmp\nautoexpire_age:3'
        }

        headers = {'Content-Type': 'application/json'}

        response = requests.post(
            url, params=APIParams(APICredentials()).get_params({}), data=json.dumps(payload), headers=headers 
        )

        print(response.json())

CSLSlicer().run()