# -*- coding: utf-8 -*-

"""
    greenbyteapi

    This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
"""

import jsonpickle
import dateutil.parser
from .controller_test_base import ControllerTestBase
from ..test_helper import TestHelper
from greenbyteapi.api_helper import APIHelper


class PlanControllerTests(ControllerTestBase):

    @classmethod
    def setUpClass(cls):
        super(PlanControllerTests, cls).setUpClass()
        cls.controller = cls.api_client.plan

    # **(BETA)** Gets a list of task categories.
    #
    #_🔐 This endpoint requires the **Plan** endpoint permission._
    #
    #_This is a beta feature. Some details might change before it is
    #released as a stable version._
    #
    def test_test_list_task_categories(self):

        # Perform the API call through the SDK function
        result = self.controller.list_task_categories()

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"categoryId":10,"title":"Scheduled maintenance"},{"categoryId":20,"title'
            '":"Unscheduled maintenance"}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


    # **(BETA)** Gets a list of downtime events.
    #
    #_🔐 This endpoint requires the **Plan** endpoint permission._
    #
    #_This is a beta feature. Some details might change before it is
    #released as a stable version._
    #
    def test_test_list_downtime_events(self):
        # Parameters for the API call
        timestamp_start = APIHelper.RFC3339DateTime.from_value('2020-01-01T00:00:00Z').datetime
        timestamp_end = APIHelper.RFC3339DateTime.from_value('2020-01-08T00:00:00Z').datetime
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        site_ids = APIHelper.json_deserialize('[1,2,3]')
        fields = APIHelper.json_deserialize('["deviceIds","timestampStart"]')
        page_size = 50
        page = 1
        use_utc = False

        # Perform the API call through the SDK function
        result = self.controller.list_downtime_events(timestamp_start, timestamp_end, device_ids, site_ids, fields, page_size, page, use_utc)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"downtimeEventId":1,"deviceIds":[1,2,3],"timestampStart":"2020-01-01T00:'
            '00:00","timestampEnd":"2020-01-02T00:00:00","comment":"Planned downtime","s'
            'iteIds":[],"taskIds":[1358]},{"downtimeEventId":2,"deviceIds":[1,2,3],"time'
            'stampStart":"2020-01-10T00:00:00","timestampEnd":"2020-01-12T00:00:00","com'
            'ment":"Unplanned downtime","siteIds":[1],"taskIds":[1359]}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


    # **(BETA)** Gets a list of site accesses.
    #
    #_🔐 This endpoint requires the **Plan** endpoint permission._
    #
    #_This is a beta feature. Some details might change before it is
    #released as a stable version._
    #
    def test_test_list_site_accesses(self):
        # Parameters for the API call
        timestamp_start = APIHelper.RFC3339DateTime.from_value('2020-01-01T00:00:00Z').datetime
        timestamp_end = APIHelper.RFC3339DateTime.from_value('2020-01-08T00:00:00Z').datetime
        device_ids = APIHelper.json_deserialize('[1,2,3]')
        site_ids = APIHelper.json_deserialize('[1,2,3]')
        fields = APIHelper.json_deserialize('["siteAccessId","timestampStart"]')
        page_size = 50
        page = 1
        use_utc = False

        # Perform the API call through the SDK function
        result = self.controller.list_site_accesses(timestamp_start, timestamp_end, device_ids, site_ids, fields, page_size, page, use_utc)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"siteAccessId":10,"siteId":18,"deviceIds":[11,12],"taskIds":[66],"siteAc'
            'cessPersonnel":[{"personnelId":1234,"firstName":"Andreas","lastName":"Jonss'
            'on","company":"Power Offtakers Inc.","phoneNumber":"456-123","vehicleRegist'
            'ration":"ABC456","comment":"Site access comment","timestampStart":"2020-04-'
            '30T10:03:00","timestampEnd":"2020-04-30T17:39:00"}],"timestampStart":"2020-'
            '01-01T12:00:00","timestampEndExpected":"2020-01-01T13:00:00","timestampEnd"'
            ':"2020-01-01T13:30:00","logOnComment":"Investigating","logOffComment":"All '
            'clear"},{"siteAccessId":11,"siteId":18,"deviceIds":[15],"taskIds":[55,56],"'
            'siteAccessPersonnel":[{"personnelId":2345,"firstName":"Andrea","lastName":"'
            'Larsson","company":"Power Offtakers Inc.","phoneNumber":"123-456","vehicleR'
            'egistration":"ABC123","comment":"Site access comment","timestampStart":"202'
            '0-04-30T10:04:00","timestampEnd":"2020-04-30T17:39:00"}],"timestampStart":"'
            '2020-01-02T12:00:00","timestampEndExpected":"2020-01-02T13:00:00","timestam'
            'pEnd":"2020-01-02T13:30:00","logOnComment":"Investigating","logOffComment":'
            '"All clear"}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


    # **(BETA)** Gets a list of organizations.
    #
    #_🔐 This endpoint requires the **Plan** endpoint permission._
    #
    #_This is a beta feature. Some details might change before it is
    #released as a stable version._
    #
    def test_test_list_organizations(self):

        # Perform the API call through the SDK function
        result = self.controller.list_organizations()

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"organizationId":10,"name":"Power Offtakers Inc.","email":"support@power'
            '-offtakers.example.com","phone":"456-789"}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


    # **(BETA)** Gets a list of personnel.
    #
    #_🔐 This endpoint requires the **Plan** endpoint permission._
    #
    #_This is a beta feature. Some details might change before it is
    #released as a stable version._
    #
    def test_test_list_personnel(self):
        # Parameters for the API call
        fields = APIHelper.json_deserialize('["lastName","phone"]')
        page_size = 50
        page = 1

        # Perform the API call through the SDK function
        result = self.controller.list_personnel(fields, page_size, page)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json; charset=utf-8'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize(
            '[{"personnelId":5,"firstName":"Greenbyte","lastName":"Support","email":"su'
            'pport@greenbyte.com","phone":"123-456","mobile":"654-321","organization":{"'
            'organizationId":10,"name":"Power Offtakers Inc.","email":"support@power-off'
            'takers.example.com","phone":"456-789"},"qualifications":[{"qualificationId"'
            ':85,"manufacturer":"GE","qualificationType":"AP","qualificationDescription"'
            ':"Authorized Person"}],"siteInductions":[{"siteInductionId":43,"siteId":1,"'
            'dateExpires":"2020-12-01"}]}]'
            )
        received_body = APIHelper.json_deserialize(self.response_catcher.response.raw_body)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))


