from google.protobuf.timestamp_pb2 import Timestamp
from yandex.cloud.certificatemanager.v1.certificate_pb2 import (
    Certificate,
    CertificateType,
    Challenge,
    ChallengeType,
)

from tests.fixtures import STUB_FOLDER_ID

STUB_CERTIFICATE_1 = Certificate(
    id="fpqahphei3aegootoh0a",
    folder_id=STUB_FOLDER_ID,
    created_at=Timestamp(seconds=1711559410, nanos=544000000),
    name="wildcard-cert",
    description="Wildcard cert for domain",
    type=CertificateType.MANAGED,
    domains=["*.example.com", "example.com"],
    status=Certificate.Status.ISSUED,
    issuer="CN=R3,O=Let\'s Encrypt,C=US",
    subject="CN=*.example.com",
    serial="9492fe88f263d58e0b686885e8c98c0eaee",
    updated_at=Timestamp(seconds=1711559421, nanos=701000000),
    issued_at=Timestamp(seconds=1711559428, nanos=516000000),
    not_after=Timestamp(seconds=1716559440),
    not_before=Timestamp(seconds=1711559455),
    challenges=[
        Challenge(
            domain="example.com",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.example.com.",
                type="CNAME",
                value="fpqahphei3aegootoh0a.cm.yandexcloud.net.",
            ),
        ),
        Challenge(
            domain="example.com",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.example.com.",
                type="TXT",
                value="Hw6x5Kj48Xu64sNMxHd7zBrEvetzQsJAXR8wFI8zytC",
            ),
        ),
        Challenge(
            domain="example.com",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.example.com.",
                type="CNAME",
                value="fpqahphei3aegootoh0a.cm.yandexcloud.net.",
            ),
        ),
        Challenge(
            domain="example.com",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.example.com.",
                type="TXT",
                value="EwOftdMfheciHoB1L3M1cKz2NbjyFlZEMEPZ6d9N8rP",
            ),
        ),
    ],
    deletion_protection=True,
)

STUB_CERTIFICATE_2 = Certificate(
    id="fpqco0ongail3feejee1",
    folder_id="b1g0aj2nmme3adupg65e",
    created_at=Timestamp(seconds=1711559410, nanos=544000000),
    name="double-cdn",
    description="Double CDN",
    type=CertificateType.MANAGED,
    domains=["cdn.example.com", "cdn2.example.com"],
    status=Certificate.Status.ISSUED,
    issuer="CN=R3,O=Let\'s Encrypt,C=US",
    subject="CN=cdn.example.com",
    serial="40bc979fc51c312c66f13621c9c53e84d51",
    updated_at=Timestamp(seconds=1711559421, nanos=701000000),
    issued_at=Timestamp(seconds=1711559428, nanos=516000000),
    not_after=Timestamp(seconds=1716559440),
    not_before=Timestamp(seconds=1711559455),
    challenges=[
        Challenge(
            domain="cdn.example.com",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.cdn.example.com.",
                type="CNAME",
                value="fpqco0ongail3feejee1.cm.yandexcloud.net.",
            ),
        ),
        Challenge(
            domain="cdn.example.com",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.cdn.example.com.",
                type="TXT",
                value="DIzWSC8sf8Sh2iMMO7chYopq8aAiNhcuxINGDKvONEA",
            ),
        ),
        Challenge(
            domain="cdn2.example.com",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.cdn2.example.com.",
                type="CNAME",
                value="fpqco0ongail3feejee1.cm.yandexcloud.net.",
            ),
        ),
        Challenge(
            domain="cdn2.example.com",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.cdn2.example.com.",
                type="TXT",
                value="8RaeDrdPzsG6L0atqh5w1qcq3DHudQ7EZCgyQfTlA6i",
            ),
        ),
    ],
    deletion_protection=True,
)

STUB_IDNA_CERTIFICATE = Certificate(
    id="fpqix1ahwo3ijiebuu0i",
    folder_id="b1g0aj2nmme3adupg65e",
    created_at=Timestamp(seconds=1711559410, nanos=544000000),
    name="idna-test",
    description="Another idna test",
    type=CertificateType.MANAGED,
    domains=["*.xn--e1aybc.xn--p1ai", "xn--e1aybc.xn--p1ai"],
    status=Certificate.Status.ISSUED,
    issuer="CN=R3,O=Let\'s Encrypt,C=US",
    subject="CN=*.xn--e1aybc.xn--p1ai",
    serial="1929d9f7c81f25c32830ebfe29fec2b247a",
    updated_at=Timestamp(seconds=1711559421, nanos=701000000),
    issued_at=Timestamp(seconds=1711559428, nanos=516000000),
    not_after=Timestamp(seconds=1716559440),
    not_before=Timestamp(seconds=1711559455),
    challenges=[
        Challenge(
            domain="xn--e1aybc.xn--p1ai",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.xn--e1aybc.xn--p1ai.",
                type="CNAME",
                value="fpqix1ahwo3ijiebuu0i.cm.yandexcloud.net.",
            ),
        ),
        Challenge(
            domain="xn--e1aybc.xn--p1ai",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.xn--e1aybc.xn--p1ai.",
                type="TXT",
                value="r4joRe9NgOIhyYLbNOCxdSPXNjnuU95kD1VbYbM0sNd",
            ),
        ),
        Challenge(
            domain="xn--e1aybc.xn--p1ai",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.xn--e1aybc.xn--p1ai.",
                type="CNAME",
                value="fpqix1ahwo3ijiebuu0i.cm.yandexcloud.net.",
            ),
        ),
        Challenge(
            domain="xn--e1aybc.xn--p1ai",
            type=ChallengeType.DNS,
            created_at=Timestamp(seconds=1711559410, nanos=487000000),
            updated_at=Timestamp(seconds=1711559428, nanos=789000000),
            status=Challenge.Status.VALID,
            message="Create a record in your DNS provider.",
            dns_challenge=Challenge.DnsRecord(
                name="_acme-challenge.xn--e1aybc.xn--p1ai.",
                type="TXT",
                value="ShsQrb08EUXyAmJ2UVGs5LPZuoOJEwTTmhQRM5LRq9T",
            ),
        ),
    ],
    deletion_protection=True,
)

IMPORTED_CERTIFICATE = Certificate(
    id="fpqeiqu3yoose7ohnuuf",
    folder_id=STUB_FOLDER_ID,
    created_at=Timestamp(seconds=1711639027, nanos=815000000),
    name="test-cert",
    type=CertificateType.IMPORTED,
    domains="example",
    status=Certificate.Status.ISSUED,
    issuer="CN=example",
    subject="CN=example",
    serial="46c86b9e43fad217487cf0883e811af50d61d979",
    updated_at=Timestamp(seconds=1711639027, nanos=815000000),
    issued_at=Timestamp(seconds=1711639027, nanos=815000000),
    not_after=Timestamp(seconds=1873526439),
    not_before=Timestamp(seconds=1558166439),
    incomplete_chain=True,
)

HTTP_CHALLENGE_CERTIFICATE = Certificate(
    id="fpqhahxiowi7kohzeegh",
    folder_id=STUB_FOLDER_ID,
    created_at=Timestamp(seconds=1711640375, nanos=70000000),
    name="test-http",
    type=CertificateType.MANAGED,
    domains=["http.example.com"],
    status=Certificate.Status.VALIDATING,
    updated_at=Timestamp(seconds=1711640375, nanos=70000000),
    challenges=[
        Challenge(
            domain="http.example.com",
            type=ChallengeType.HTTP,
            created_at=Timestamp(seconds=1711640375, nanos=70000000),
            updated_at=Timestamp(seconds=1711640377, nanos=724000000),
            status=Challenge.Status.PENDING,
            message="Create a file in your web server\'s base directory.",
            http_challenge=Challenge.HttpFile(
                url="http://http.example.com/.well-known/acme-challenge/Ocigx_DuIcj50N9tRfUx8sdJC8tCBQ3vRrtUP_rro8ZY",
                content="Ocigx_DuIcj50N9tRfUx8sdJC8tCBQ3vRrtUP_rro8ZY.QRuoX6yZYcbmuw_Gb0DQbwXBFJWZkMr_DMCa2yaVeQ",
            ),
        )
    ],
)
