from animate.svg import Svg
from animate.elastic import Elastic
from animate.animate import Animate
from animate.elastictwo import ElasticTwo
from animate.image import Image

radius = 50

farmer_x = 100
farmer_y = 100
cooperative_x = 250
cooperative_y = 300
supplier_x = 400
supplier_y = 100
ecx_x = 700
ecx_y = 100
exporter_x = 1000
exporter_y = 100
cqicc_x = 1300
cqicc_y = 300
buyer_x = 1600
buyer_y = 300
ledger_start_x = 50
ledger_end_x = 1650
ledger_y = 500


with open("blockchain.svg", "w") as out:
    draw = Svg(out)
    draw.init()
    # <a href="https://www.freepik.com/icons/farm">Icon by Freepik</a>
    draw.image("farmer", "png", farmer_x, farmer_y, 100, 0)
    # <a href="https://www.freepik.com/icons/cooperative">Icon by Freepik</a>
    draw.image("cooperative", "png", cooperative_x, cooperative_y, 100, 0)
    # <a href="https://www.freepik.com/icons/suplier">Icon by Freepik</a>
    draw.image("supplier", "png", supplier_x, supplier_y, 100, 0)
    # <a href="https://www.freepik.com/icons/market">Icon by Freepik</a>
    draw.image("ecx", "png", ecx_x, ecx_y, 100, 0)
    # <a href="https://www.freepik.com/icons/export">Icon by Freepik</a>
    draw.image("exporter", "png", exporter_x, exporter_y, 100, 0)
    # <a href="https://www.freepik.com/icons/authority">Icon by Freepik</a>
    draw.image("cqicc", "png", cqicc_x, cqicc_y, 100, 0)
    # <a href="https://www.freepik.com/icons/buyer>Icon by Freepik</a>
    draw.image("buyer", "png", buyer_x, buyer_y, 100, 0)

    # START MAIN PROCESS
    start_type = ElasticTwo("start", "0s;ack_coop_buyertwo.end")
    Animate(out, start_type).animate(
        farmer_x, farmer_y + radius, farmer_x, ledger_y, 0.5, 0
    )
    coffee1_type = Image("coffee1", "coffee", "png", 60, "starttwo.end")
    Animate(out, coffee1_type).animate(farmer_x, farmer_y, supplier_x, supplier_y, 2.0)
    # deliver_type = Elastic("deliver", "starttwo.end")
    # Animate(out, deliver_type).animate(
    #     farmer_x, farmer_y, supplier_x - radius, supplier_y, 2.0, 0
    # )
    ack_type = ElasticTwo("ack", "coffee1.end")
    Animate(out, ack_type).animate(
        supplier_x, supplier_y + radius, supplier_x, ledger_y, 0.5, 0
    )
    coffee2_type = Image("coffee2", "coffee", "png", 60, "acktwo.end")
    Animate(out, coffee2_type).animate(supplier_x, supplier_y, ecx_x, ecx_y, 2.0)
    # deliver_ecx_type = Elastic("deliver_ecx", "acktwo.end")
    # Animate(out, deliver_ecx_type).animate(
    #     supplier_x, supplier_y, ecx_x, ecx_y, 2.0, radius
    # )
    ack_ecx_type = ElasticTwo("ack_ecx", "coffee2.end")
    Animate(out, ack_ecx_type).animate(ecx_x, ecx_y + radius, ecx_x, ledger_y, 0.5, 0)
    coffee3_type = Image("coffee3", "coffee", "png", 60, "ack_ecxtwo.end")
    Animate(out, coffee3_type).animate(ecx_x, ecx_y, exporter_x, exporter_y, 2.0)
    # deliver_exporter_type = Elastic("deliver_exporter", "ack_ecxtwo.end")
    # Animate(out, deliver_exporter_type).animate(
    #     ecx_x, ecx_y, exporter_x, exporter_y, 2.0, radius
    # )
    ack_exporter_type = ElasticTwo("ack_exporter", "coffee3.end")
    Animate(out, ack_exporter_type).animate(
        exporter_x, exporter_y + radius, exporter_x, ledger_y, 0.5, 0
    )
    coffee4_type = Image("coffee4", "coffee", "png", 60, "ack_exportertwo.end")
    Animate(out, coffee4_type).animate(exporter_x, exporter_y, cqicc_x, cqicc_y, 2.0)
    # check_quality_type = Elastic("check_quality", "ack_exportertwo.end")
    # Animate(out, check_quality_type).animate(
    #     exporter_x, exporter_y, cqicc_x, cqicc_y, 2, radius
    # )
    ack_check_type = ElasticTwo("ack_check", "coffee4.end")
    Animate(out, ack_check_type).animate(
        cqicc_x, cqicc_y + radius, cqicc_x, ledger_y, 0.5, 0
    )
    coffee5_type = Image("coffee5", "coffee", "png", 60, "ack_checktwo.end")
    Animate(out, coffee5_type).animate(cqicc_x, cqicc_y, buyer_x, buyer_y, 2.0)
    # buyer_type = Elastic("buyer", "ack_checktwo.end")
    # Animate(out, buyer_type).animate(cqicc_x, cqicc_y, buyer_x, buyer_y, 2, radius)
    ack_buyer_type = ElasticTwo("ack_buyer", "coffee5.end")
    Animate(out, ack_buyer_type).animate(
        buyer_x, buyer_y + radius, buyer_x, ledger_y, 0.5, 0
    )

    # START COOPERATIVE/UNION PROCESS
    start_coop_type = ElasticTwo("start_coop", "ack_buyertwo.end")
    Animate(out, start_coop_type).animate(
        farmer_x, farmer_y + radius, farmer_x, ledger_y, 0.5, 0
    )
    coffee_coop1_type = Image("coffee_coop1", "coffee", "png", 60, "start_cooptwo.end")
    Animate(out, coffee_coop1_type).animate(
        farmer_x, farmer_y, cooperative_x, cooperative_y, 2.0
    )
    ack_coop_type = ElasticTwo("ack_coop", "coffee_coop1.end")
    Animate(out, ack_coop_type).animate(
        cooperative_x, cooperative_y + radius, cooperative_x, ledger_y, 0.5, 0
    )
    coffee_coop2_type = Image("coffee_coop2", "coffee", "png", 60, "ack_cooptwo.end")
    Animate(out, coffee_coop2_type).animate(
        cooperative_x, cooperative_y, cqicc_x, cqicc_y, 6.0
    )
    ack_coop_cqicc_type = ElasticTwo("ack_coop_cqicc", "coffee_coop2.end")
    Animate(out, ack_coop_cqicc_type).animate(
        cqicc_x, cqicc_y + radius, cqicc_x, ledger_y, 0.5, 0
    )
    coffee_coop3_type = Image("coffee_coop3", "coffee", "png", 60, "ack_coop_cqicctwo.end")
    Animate(out, coffee_coop3_type).animate(
        cqicc_x, cqicc_y, buyer_x, buyer_y, 2.0
    )
    ack_coop_buyer_type = ElasticTwo("ack_coop_buyer", "coffee_coop3.end")
    Animate(out, ack_coop_buyer_type).animate(
        buyer_x, buyer_y + radius, buyer_x, ledger_y, 0.5, 0
    )

    draw.line(
        ledger_start_x, ledger_y, ledger_end_x, ledger_y, "#eaa; stroke-width: 40"
    )

    draw.end()
