# Path: src/schemas/messages.py
# class MessageStatus(str, Enum):
#     """
#     Combined MandrillMessageStatus and MessageBirdMessageStatus
# 
#     Should match MESSAGE_STATUSES sql enum
#     """
# 
#     render_failed = 'render_failed'
#     send_request_failed = 'send_request_failed'
# 
#     send = 'send'
#     deferral = 'deferral'
#     hard_bounce = 'hard_bounce'
#     soft_bounce = 'soft_bounce'
#     open = 'open'
#     click = 'click'
#     spam = 'spam'
#     unsub = 'unsub'
#     reject = 'reject'
# 
#     # used for sms
#     scheduled = 'scheduled'
#     # send = 'send'  # above
#     buffered = 'buffered'
#     delivered = 'delivered'
#     expired = 'expired'
#     delivery_failed = 'delivery_failed'


import hashlib
import hmac
import json
import uuid
from buildpg import V, Values
from datetime import date, datetime, timedelta, timezone
from foxglove import glove
from foxglove.db.helpers import SyncDb
from operator import itemgetter
from pytest_toolbox.comparison import RegexStr
from starlette.testclient import TestClient
from urllib.parse import urlencode
from src.schemas.messages import MessageStatus
    assert r.json()['events'] == [
        {'status': 'Sent', 'datetime': '2032-06-01T00:00:00+00:00'},
        {'status': 'Sent', 'datetime': '2032-06-02T02:00:00+00:00'},
        {'status': 'Sent', 'datetime': '2032-06-03T04:00:00+00:00'},
    ]


def test_invalid_message_id(cli, sync_db: SyncDb, settings, send_email):
    msg_ext_id = send_email(
        company_code='test-details', recipients=[{'first_name': 'Foo', 'address': 'foobar@testing.com'}]
    )
    message_id = sync_db.fetchval_b('select id from messages where :where', where=V('external_id') == msg_ext_id)
    r = cli.get(modify_url(f'/messages/email-test/{message_id}/', settings, 'not_real_company'))
    assert r.status_code == 404

    r = cli.get(modify_url(f'/messages/email-test/999{message_id}/', settings, 'test-details'))
    assert r.status_code == 404


def test_many_events(cli, settings, send_email, sync_db: SyncDb):
    msg_ext_id = send_email(
        company_code='test-details', recipients=[{'first_name': 'Foo', 'address': 'foobar@testing.com'}]
    )
    message_id = sync_db.fetchval_b('select id from messages where :where', where=V('external_id') == msg_ext_id)
    sync_db.executemany_b(
        'insert into events (:values__names) values :values',
        [
            Values(
                ts=(datetime(2032, 6, 1) + timedelta(days=i, hours=i * 2)).replace(tzinfo=timezone.utc),
                message_id=message_id,

# Path: src/schemas/messages.py
# class MessageStatus(str, Enum):
#     """
#     Combined MandrillMessageStatus and MessageBirdMessageStatus
# 
#     Should match MESSAGE_STATUSES sql enum
#     """
# 
#     render_failed = 'render_failed'
#     send_request_failed = 'send_request_failed'
# 
#     send = 'send'
#     deferral = 'deferral'
#     hard_bounce = 'hard_bounce'
#     soft_bounce = 'soft_bounce'
#     open = 'open'
#     click = 'click'
#     spam = 'spam'
#     unsub = 'unsub'
#     reject = 'reject'
# 
#     # used for sms
#     scheduled = 'scheduled'
#     # send = 'send'  # above
#     buffered = 'buffered'
#     delivered = 'delivered'
#     expired = 'expired'
#     delivery_failed = 'delivery_failed'


# Path: tests/test_user_display.py
import hashlib
import hmac
import json
import uuid
from buildpg import V, Values
from datetime import date, datetime, timedelta, timezone
from foxglove import glove
from foxglove.db.helpers import SyncDb
from operator import itemgetter
from pytest_toolbox.comparison import RegexStr
from starlette.testclient import TestClient
from urllib.parse import urlencode
from src.schemas.messages import MessageStatus

    assert r.json()['events'] == [
        {'status': 'Sent', 'datetime': '2032-06-01T00:00:00+00:00'},
        {'status': 'Sent', 'datetime': '2032-06-02T02:00:00+00:00'},
        {'status': 'Sent', 'datetime': '2032-06-03T04:00:00+00:00'},
    ]


def test_invalid_message_id(cli, sync_db: SyncDb, settings, send_email):
    msg_ext_id = send_email(
        company_code='test-details', recipients=[{'first_name': 'Foo', 'address': 'foobar@testing.com'}]
    )
    message_id = sync_db.fetchval_b('select id from messages where :where', where=V('external_id') == msg_ext_id)
    r = cli.get(modify_url(f'/messages/email-test/{message_id}/', settings, 'not_real_company'))
    assert r.status_code == 404

    r = cli.get(modify_url(f'/messages/email-test/999{message_id}/', settings, 'test-details'))
    assert r.status_code == 404


def test_many_events(cli, settings, send_email, sync_db: SyncDb):
    msg_ext_id = send_email(
        company_code='test-details', recipients=[{'first_name': 'Foo', 'address': 'foobar@testing.com'}]
    )
    message_id = sync_db.fetchval_b('select id from messages where :where', where=V('external_id') == msg_ext_id)
    sync_db.executemany_b(
        'insert into events (:values__names) values :values',
        [
            Values(
                ts=(datetime(2032, 6, 1) + timedelta(days=i, hours=i * 2)).replace(tzinfo=timezone.utc),
                message_id=message_id,

                status=MessageStatus.send,