import requests as requests_http
from . import utils
from codat.models import operations
from typing import Optional

class SyncStatus:
    _client: requests_http.Session
    _security_client: requests_http.Session
    _server_url: str
    _language: str
    _sdk_version: str
    _gen_version: str

    def __init__(self, client: requests_http.Session, security_client: requests_http.Session, server_url: str, language: str, sdk_version: str, gen_version: str) -> None:
        self._client = client
        self._security_client = security_client
        self._server_url = server_url
        self._language = language
        self._sdk_version = sdk_version
        self._gen_version = gen_version
        
    def get_last_successful_sync(self, request: operations.GetLastSuccessfulSyncRequest) -> operations.GetLastSuccessfulSyncResponse:
        r"""Last successful sync
        Gets the status of the last successfull sync
        """
        
        base_url = self._server_url
        
        url = utils.generate_url(operations.GetLastSuccessfulSyncRequest, base_url, '/companies/{companyId}/sync/expenses/syncs/lastSuccessful/status', request)
        
        
        client = self._security_client
        
        http_res = client.request('GET', url)
        content_type = http_res.headers.get('Content-Type')

        res = operations.GetLastSuccessfulSyncResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[operations.GetLastSuccessfulSync200ApplicationJSON])
                res.get_last_successful_sync_200_application_json_object = out

        return res

    def get_latest_sync(self, request: operations.GetLatestSyncRequest) -> operations.GetLatestSyncResponse:
        r"""Latest sync status
        Gets the latest sync status
        """
        
        base_url = self._server_url
        
        url = utils.generate_url(operations.GetLatestSyncRequest, base_url, '/companies/{companyId}/sync/expenses/syncs/latest/status', request)
        
        
        client = self._security_client
        
        http_res = client.request('GET', url)
        content_type = http_res.headers.get('Content-Type')

        res = operations.GetLatestSyncResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[operations.GetLatestSync200ApplicationJSON])
                res.get_latest_sync_200_application_json_object = out

        return res

    def get_sync_by_id(self, request: operations.GetSyncByIDRequest) -> operations.GetSyncByIDResponse:
        r"""Get Sync status
        Get the sync status for a specified sync
        """
        
        base_url = self._server_url
        
        url = utils.generate_url(operations.GetSyncByIDRequest, base_url, '/companies/{companyId}/sync/expenses/syncs/{syncId}/status', request)
        
        
        client = self._security_client
        
        http_res = client.request('GET', url)
        content_type = http_res.headers.get('Content-Type')

        res = operations.GetSyncByIDResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[operations.GetSyncByID200ApplicationJSON])
                res.get_sync_by_id_200_application_json_object = out

        return res

    def list_syncs(self, request: operations.ListSyncsRequest) -> operations.ListSyncsResponse:
        r"""List sync statuses
        Gets a list of sync statuses
        """
        
        base_url = self._server_url
        
        url = utils.generate_url(operations.ListSyncsRequest, base_url, '/companies/{companyId}/sync/expenses/syncs/list/status', request)
        
        
        client = self._security_client
        
        http_res = client.request('GET', url)
        content_type = http_res.headers.get('Content-Type')

        res = operations.ListSyncsResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[list[operations.ListSyncs200ApplicationJSON]])
                res.list_syncs_200_application_json_objects = out

        return res

    