<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/** 下注订单头 {@see ticket_orders} */
final class TicketOrder extends Model
{
    protected $fillable = [
        'order_no',
        'player_id',
        'draw_id',
        'currency_code',
        'total_bet_amount',
        'total_rebate_amount',
        'total_actual_deduct',
        'total_estimated_payout',
        'status',
        'submit_source',
        'client_trace_id',
        'play_config_version_no',
        'odds_version_no',
        'risk_cap_version_no',
    ];

    protected function casts(): array
    {
        return [
            'player_id' => 'integer',
            'draw_id' => 'integer',
            'total_bet_amount' => 'integer',
            'total_rebate_amount' => 'integer',
            'total_actual_deduct' => 'integer',
            'total_estimated_payout' => 'integer',
            'play_config_version_no' => 'integer',
            'odds_version_no' => 'integer',
            'risk_cap_version_no' => 'integer',
        ];
    }

    public function player(): BelongsTo
    {
        return $this->belongsTo(Player::class);
    }

    public function draw(): BelongsTo
    {
        return $this->belongsTo(Draw::class);
    }

    public function items(): HasMany
    {
        return $this->hasMany(TicketItem::class, 'order_id');
    }
}
