"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""

from __future__ import annotations
import dataclasses
import dateutil.parser
from ..shared import creditnotelineitem as shared_creditnotelineitem
from ..shared import customerminified as shared_customerminified
from dataclasses_json import Undefined, dataclass_json
from datetime import datetime
from enum import Enum
from orb import utils
from typing import Optional



@dataclasses.dataclass
class CreditNoteDiscounts:
    pass



@dataclasses.dataclass
class CreditNoteMaximumAmountAdjustment:
    r"""The maximum amount applied on the original invoice"""
    


class CreditNoteReason(str, Enum):
    DUPLICATE = 'Duplicate'
    FRAUDULENT = 'Fraudulent'
    ORDER_CHANGE = 'Order change'
    PRODUCT_UNSATISFACTORY = 'Product unsatisfactory'

class CreditNoteType(str, Enum):
    REFUND = 'refund'
    ADJUSTMENT = 'adjustment'


@dataclass_json(undefined=Undefined.EXCLUDE)

@dataclasses.dataclass
class CreditNote:
    r"""The [Credit Note](/guides/invoicing/credit-notes) resource represents a credit that has been applied to a
    particular invoice.
    """
    created_at: datetime = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('created_at'), 'encoder': utils.datetimeisoformat(False), 'decoder': dateutil.parser.isoparse }})
    r"""The creation time of the resource in Orb."""
    credit_note_number: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('credit_note_number') }})
    r"""The unique identifier for credit notes."""
    credit_note_pdf: Optional[str] = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('credit_note_pdf') }})
    r"""A URL to a PDF of the credit note."""
    customer: shared_customerminified.CustomerMinified = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('customer') }})
    discounts: list[CreditNoteDiscounts] = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('discounts') }})
    r"""Any discounts applied on the original invoice."""
    id: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('id') }})
    r"""The Orb id of this credit note."""
    invoice_id: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('invoice_id') }})
    r"""The id of the invoice resource that this credit note is applied to."""
    line_items: list[shared_creditnotelineitem.CreditNoteLineItem] = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('line_items') }})
    r"""All of the line items associated with this credit note."""
    maximum_amount_adjustment: Optional[CreditNoteMaximumAmountAdjustment] = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('maximum_amount_adjustment') }})
    r"""The maximum amount applied on the original invoice"""
    memo: Optional[str] = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('memo') }})
    r"""An optional memo supplied on the credit note."""
    minimum_amount_refunded: Optional[str] = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('minimum_amount_refunded') }})
    r"""Any credited amount from the applied minimum on the invoice."""
    reason: CreditNoteReason = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('reason') }})
    subtotal: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('subtotal') }})
    r"""The total prior to any creditable invoice-level discounts or minimums."""
    total: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('total') }})
    r"""The total including creditable invoice-level discounts or minimums, and tax."""
    type: CreditNoteType = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('type') }})
    voided_at: Optional[datetime] = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('voided_at'), 'encoder': utils.datetimeisoformat(False), 'decoder': dateutil.parser.isoparse }})
    r"""The time at which the credit note was voided in Orb, if applicable."""
    

