from http import HTTPMethod, HTTPStatus

from layercake.dynamodb import DynamoDBPersistenceLayer

from ...conftest import HttpApiProxy, LambdaContext


def test_checkout(
    app,
    seeds,
    http_api_proxy: HttpApiProxy,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    r = app.lambda_handler(
        http_api_proxy(
            raw_path='/orders',
            method=HTTPMethod.POST,
            body={
                'org_id': 'f6000f79-6e5c-49a0-952f-3bda330ef278',
                'cnpj': '00000000000191',
                'name': 'Branco do Brasil',
                'email': 'sergio@somosbeta.com.br',
                'payment_method': 'MANUAL',
                'user': {
                    'id': '15bacf02-1535-4bee-9022-19d106fd7518',
                    'name': 'Sérgio R Siqueira',
                },
                'address': {
                    'city': 'Curitiba',
                    'postcode': '81280350',
                    'neighborhood': 'Cidade Industrial',
                    'address1': 'Rua Monsenhor Ivo Zanlorenzi',
                    'address2': 'nº 5190, ap 1802',
                    'state': 'PR',
                },
                'items': [
                    {
                        'id': 'e1c44881-2fe3-484e-ada2-12b6bf5b9398',
                        'name': 'NR-35 Segurança nos Trabalhos em Altura',
                        'quantity': 2,
                        'unit_price': 119,
                    }
                ],
            },
        ),
        lambda_context,
    )
    print(r)
    assert r['statusCode'] == HTTPStatus.CREATED


def test_checkout_from_user(
    app,
    seeds,
    http_api_proxy: HttpApiProxy,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    r = app.lambda_handler(
        http_api_proxy(
            raw_path='/orders',
            method=HTTPMethod.POST,
            body={
                'user_id': '15bacf02-1535-4bee-9022-19d106fd7518',
                'cpf': '07879819908',
                'name': 'Sérgio R Siqueira',
                'email': 'sergio@somosbeta.com.br',
                'payment_method': 'MANUAL',
                'address': {
                    'city': 'Curitiba',
                    'postcode': '81280350',
                    'neighborhood': 'Cidade Industrial',
                    'address1': 'Rua Monsenhor Ivo Zanlorenzi',
                    'address2': 'nº 5190, ap 1802',
                    'state': 'PR',
                },
                'items': [
                    {
                        'id': 'e1c44881-2fe3-484e-ada2-12b6bf5b9398',
                        'name': 'NR-35 Segurança nos Trabalhos em Altura',
                        'quantity': 2,
                        'unit_price': 119,
                    }
                ],
            },
        ),
        lambda_context,
    )
    print(r)
    assert r['statusCode'] == HTTPStatus.CREATED
