<?php

namespace Tests\Unit;

use App\Models\LhcOrder;
use PHPUnit\Framework\TestCase;

class LhcOrderTest extends TestCase
{
    public function test_it_preserves_stored_profit_and_loss(): void
    {
        $order = new LhcOrder();
        $order->setRawAttributes([
            'profit_and_loss' => '12.345',
            'lottery_status' => LhcOrder::STATUS_WIN,
        ]);

        $this->assertSame('12.345', $order->profit_and_loss);
    }

    public function test_it_calculates_missing_profit_and_loss_for_settled_order(): void
    {
        $order = new LhcOrder();
        $order->setRawAttributes([
            'profit_and_loss' => null,
            'lottery_status' => LhcOrder::STATUS_WIN,
            'win_amount' => '150.00',
            'total_amount' => '100.00',
            'amount' => '50.00',
        ]);

        $this->assertSame('50.00', $order->profit_and_loss);
    }

    public function test_it_returns_zero_for_unsettled_order(): void
    {
        $order = new LhcOrder();
        $order->setRawAttributes([
            'profit_and_loss' => null,
            'lottery_status' => LhcOrder::STATUS_STAY,
            'win_amount' => '0.00',
            'total_amount' => '100.00',
        ]);

        $this->assertSame('0.00', $order->profit_and_loss);
    }
}
