"""Tests for htsget models."""

from __future__ import annotations

from ai4gh.specs.htsget.models import (
    HtsgetClass,
    HtsgetFormat,
    HtsgetTicket,
    HtsgetTicketData,
    HtsgetURL,
)


class TestHtsgetFormat:
    def test_values(self) -> None:
        assert HtsgetFormat.BAM.value == "BAM"
        assert HtsgetFormat.CRAM.value == "CRAM"
        assert HtsgetFormat.VCF.value == "VCF"
        assert HtsgetFormat.BCF.value == "BCF"


class TestHtsgetClass:
    def test_values(self) -> None:
        assert HtsgetClass.header.value == "header"
        assert HtsgetClass.body.value == "body"


class TestHtsgetURL:
    def test_basic(self) -> None:
        url = HtsgetURL(url="https://example.com/data/block1")
        assert url.url == "https://example.com/data/block1"
        assert url.headers is None
        assert url.data_class is None

    def test_with_headers(self) -> None:
        url = HtsgetURL(
            url="https://example.com/data/block1",
            headers={"Authorization": "Bearer token"},
        )
        assert url.headers is not None
        assert url.headers["Authorization"] == "Bearer token"

    def test_with_class(self) -> None:
        url = HtsgetURL(
            url="https://example.com/data/header",
            data_class=HtsgetClass.header,
        )
        assert url.data_class == HtsgetClass.header


class TestHtsgetTicketData:
    def test_basic(self) -> None:
        data = HtsgetTicketData(
            format=HtsgetFormat.BAM,
            urls=[HtsgetURL(url="https://example.com/block1")],
        )
        assert data.format == HtsgetFormat.BAM
        assert len(data.urls) == 1
        assert data.md5 is None

    def test_with_md5(self) -> None:
        data = HtsgetTicketData(
            format=HtsgetFormat.VCF,
            urls=[],
            md5="abc123",
        )
        assert data.md5 == "abc123"


class TestHtsgetTicket:
    def test_basic(self) -> None:
        ticket = HtsgetTicket(
            htsget=HtsgetTicketData(
                format=HtsgetFormat.CRAM,
                urls=[
                    HtsgetURL(url="https://example.com/header", data_class=HtsgetClass.header),
                    HtsgetURL(url="https://example.com/body", data_class=HtsgetClass.body),
                ],
            )
        )
        assert ticket.htsget.format == HtsgetFormat.CRAM
        assert len(ticket.htsget.urls) == 2
