<?php
if ( ! defined( 'ABSPATH' ) ) exit;

class PBUAIV_Credit_Note extends PBUAIV_Document {
    protected string $type  = 'credit_note';
    protected string $label = '';

    public function __construct( WC_Order $order ) {
        $this->label = __( 'Credit Note', 'pb-invoicing-system' );
        parent::__construct( $order );
    }
    protected function get_type()  : string { return 'credit_note'; }
    protected function get_label() : string { return __( 'Credit Note', 'pb-invoicing-system' ); }

    protected function compile() : array {
        $data = parent::compile();
        // Credit notes reference the original invoice
        $original_number = $this->order->get_meta( '_pbuaiv_invoice_number', true );
        $data['referenced_invoice'] = $original_number ?: '';
        $data['label'] = __( 'Credit Note', 'pb-invoicing-system' );
        // Negate amounts for display purposes
        $data['total']         = -abs( $data['total'] );
        $data['vat_amount']    = -abs( $data['vat_amount'] );
        $data['vat_amount_aed']= -abs( $data['vat_amount_aed'] );
        return $data;
    }
}
