<?php



namespace Daniv04\HaciendaPackage\Models;

use Daniv04\HaciendaPackage\Enums\ReceiptType;
use Daniv04\HaciendaPackage\Enums\ReceiptStatus;
use Daniv04\HaciendaPackage\Enums\HaciendaStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;


class Receipt extends Model
{

    use HasFactory;

     /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'receipts';

    protected $fillable = [
        'receipt_type',
        'ui_key', 
        'consecutive_number',
        'emission_date',
        'sent_to_hacienda_at',
        'receipt_status',
        'signed_xml',
        'hacienda_status',

        'sell_condition',
        'total_amount', 
        'tax_amount',
        'total_discount',
        'total_voucher',
        'currency',
        'exchange_rate',

        'emissor_name',
        'emissor_number',
        'emissor_type_identification',
        'receiver_name',
        'receiver_number',
        'receiver_type_identification',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'emission_date' => 'datetime',
        'sent_to_hacienda_at' => 'datetime',
        'receipt_type' => ReceiptType::class,
        'receipt_status' => ReceiptStatus::class,
        'hacienda_status' => HaciendaStatus::class,
    ];

    public function payload()
    {
        return $this->hasOne(ReceiptPayload::class, 'receipt_id');
    }

    public function haciendaResponse()
    {
        return $this->hasOne(HaciendaResponse::class, 'receipt_id');
    }

    
}