// Exact Rust translation of LibreMetaverse.Tests/StartAuctionTests.cs.
// Source SHA-256: 7087a3957277dc76a018ff3478e69c556f33a890ada9ad2c8c53f3fc34ec7375

use libremetaverse::packets::{
    Packet, PacketType, ViewerStartAuctionPacket, ViewerStartAuctionPacketAgentDataBlock,
    ViewerStartAuctionPacketParcelDataBlock,
};
use libremetaverse::{GridClient, Simulator};
use libremetaverse_types::UUID;

fn uuid() -> UUID {
    UUID::random().expect("UUID Random")
}

// parity-case: LibreMetaverse.Tests/StartAuctionTests.cs::StartAuctionTests.ViewerStartAuctionPacket_RoundTripsAgentAndParcelFields::test f37ef06cfba37754effe04a0bb0edfa159c761b811a05efd95157896756bef16 translated
#[test]
fn viewer_start_auction_packet_round_trips_agent_and_parcel_fields() {
    let agent = uuid();
    let session = uuid();
    let snapshot = uuid();
    let packet = ViewerStartAuctionPacket {
        agent_data: ViewerStartAuctionPacketAgentDataBlock {
            agent_id: agent,
            session_id: session,
        },
        parcel_data: ViewerStartAuctionPacketParcelDataBlock {
            local_id: 12_345,
            snapshot_id: snapshot,
        },
    };
    let bytes = packet.to_bytes_with_method().unwrap();
    let mut end = i32::try_from(bytes.len()).expect("packet length fits Int32") - 1;
    let built =
        Packet::build_packet_with_bytes_int32_bytes(bytes.clone(), &mut end, Vec::new()).unwrap();
    assert_eq!(built.type_, PacketType::ViewerStartAuction);
    let mut position = 0;
    let parsed = ViewerStartAuctionPacket::new_with_bytes_int32(bytes, &mut position).unwrap();
    assert_eq!(parsed.agent_data.agent_id, agent);
    assert_eq!(parsed.agent_data.session_id, session);
    assert_eq!(parsed.parcel_data.local_id, 12_345);
    assert_eq!(parsed.parcel_data.snapshot_id, snapshot);
}

// parity-case: LibreMetaverse.Tests/StartAuctionTests.cs::StartAuctionTests.StartAuction_DoesNotThrow::test deec194333b480dabb3f6e6d96b360a29d11a40ca1103117fc7ce5cdb80d6eb0 translated
#[test]
fn start_auction_does_not_throw() {
    let client = GridClient::new().expect("GridClient constructor");
    let simulator = Simulator::new(
        GridClient::new().expect("simulator GridClient constructor"),
        "127.0.0.1:13".parse().unwrap(),
        0,
        None,
        None,
    )
    .expect("Simulator constructor");
    client
        .parcels()
        .start_auction(simulator, 1, uuid())
        .unwrap();
}
