// InvoicePrintReq 發票列印
export type InvoicePrintReq = {
    MerchantID: string,
    // 發票號碼
    InvoiceNo: string,
    // 發票日期
    InvoiceDate: string,
    // 列印方式
    // 1: 一般列印單面(預設)
    // 2: 一般列印雙面
    // 3: 熱感應紙影印
    // 4: B2B A4(僅限帶有統編的發票才能使用)
    // 5: B2B A5雙面(僅限帶有統編的發票才能使用)
    PrintStyle?: 1 | 2 | 3 | 4 | 5,

    // 是否顯示明細
    // 1: 顯示
    // 2: 不顯示
    IsShowingDetail?: 1 | 2,
}
export type InvoicePrintResp = {
    RtnCode: number,
    RtnMsg: string,
    // 發票列印網址
    // 該網址有效時間為，從呼叫此列印API開始計算 1小時內有效
    InvoiceHtml: string,
}

export enum DataType {
    JSON = 1,
    CSV = 2,
}

export enum QueryAward {
    All = 0,
    Yes = 1,
    No = 2,
}

export type IssueListQuery = {
    MerchantID: string,
    // 查詢開立日期(起)
    BeginDate: string,
    // 查詢開立日期(迄)
    EndDate: string,
    NumPerPage: number, // max: 200
    ShowingPage: number,
    DataType?: DataType, //1: JASON格式 2: CSV格式
    Query_Award?: QueryAward // 0:全部 1:是 2:否
    Query_Invalid?: 0 | 1 | 2 // 0:全部 1:是 2:否
    Query_Print?: 0 | 1 | 2 | 3 // 0:全部 1:是 2:否 3:已處理
    Query_Upload?: 0 | 1 | 2 | 3 // 0:全部 1:是 2:否 3:上傳失效
    Query_Identifier?: 0 | 1 | 2 // 0:全部 1:是 2:否
    Query_TaxType?: 0 | 1 | 2 | 3 | 4 | 9 // 0:全部 1:應稅 2:零稅率 3:免稅 4:應稅(特種稅率) 9:混合應稅與免稅或零稅率
    Query_Category?: 0 | 1 | 2 | 3 // 0:全部 1:B2C 2:POS 3:離線
    Query_Customer_Name?: string // 客戶名稱
    Query_Customer_Phone?: string // 客戶電話
}

export type GetIssueListOutput = {
    RtnCode: number,
    RtnMsg: string,
    TotalCount: number,
    ShowingPage: number,
    InvoiceData: {
        IIS_Number: string,
        IIS_Relate_Number: string,
        IIS_Identifier: string,
        IIS_Clearance_Mark: "1" | "2", //1: 非經海關出口 2: 經海關出口
        IIS_Category: "B2C" | "B2B"
        // 課稅別
        // 0：全部(預設)
        // 1：應稅
        // 2：零稅
        // 3：免稅
        // 4：特種稅率
        // 9：混合稅率
        IIS_Tax_Type: "1" | "2" | "3" | "4" | "9"
        // 稅率
        // 小數點2位
        IIS_Tax_Rate: number,
        // 稅額
        IIS_Tax_Amount: number,
        // 發票金額
        IIS_Sales_Amount: number,
        // 發票開立時間
        IIS_Create_Date: string,
        // 發票開立狀態 1:已開立 0:未開立
        IIS_Issue_Status: "1" | "0"
        // 發票上傳狀態 1:已上傳 0:未上傳
        IIS_Upload_Status: "1" | "0"
        // 發票上傳時間
        IIS_Upload_Date: string,

        // 發票上傳後接收狀態
        // C: 成功
        // E: 失敗
        // G: 處理中(待財政部回覆狀態)
        // F: 失敗(待財政部回覆狀態)
        IIS_Turnkey_Status: "C" | "E" | "F" | "G"

        //折讓剩餘金額
        IIS_Remain_Allowance_Amt: number,
        // 是否列印發票
        // 1:列印
        // 0:不列印
        IIS_Print_Flag: "1" | "0", // 1:列印 0: 不列印

        // 是否中獎
        // 1:已中獎
        // 0:未中獎
        IIS_Award_Flag: "1" | "0", // 1:已中獎 0:未中獎 X:有統編的發票
        //中獎種類
        /**
         *
         * 中獎種類
         *
         * 12：雲端發票獎800元
         * 11：雲端發票獎500元
         * 10：雲端發票獎100萬元
         * 9：雲端發票獎2000元
         * 8：特別獎 一千萬　
         * 7：特獎 二百萬元
         * 1：頭獎 二十萬元
         * 2：二獎 四萬元
         * 3：三獎 一萬元
         * 4：四獎 四千元
         * 5：五獎 一千元
         * 6：六獎 二百元
         * 0：未中獎
         */
        IIS_Award_Type: string
        /**
         * 載具類別
         * 空值：無載具
         * 1：為綠界電子發票載具
         * 2：為消費者自然人憑證
         * 3：為消費者手機條碼
         */
        IIS_Carrier_Type: "1" | "2" | "3"
        // 載具編號
        IIS_Carrier_Num: string,
        // 愛心碼
        IIS_Love_Code: string, // 愛心碼
    }[]
}
export type ECPayInstance = {
    // 開立發票
    Issue: (input: IssueData) => Promise<IssueResp>,

    // 開立折讓
    Allowance: (input: AllowanceInput) => Promise<AllowanceResp>,

    // 作廢發票
    Invalid: (input: InvoiceInvalidInput) => Promise<InvoiceInvalidResp>,

    // 作廢折讓
    AllowanceInvalid: (input: AllowanceInvalidInput) => Promise<AllowanceInvalidResp>,

    // 取得發票
    GetIssue: (input: QueryWithRelateNumber | QueryWithInvoiceNumberAndDate) => Promise<QueryInvoiceResp>,

    // 查詢特定多筆發票
    GetIssueList: (input: IssueListQuery) => Promise<GetIssueListOutput>,

    // 列印發票
    InvoicePrint: (input: InvoicePrintReq) => Promise<InvoicePrintResp>,

    // 查詢折讓
    GetAllowanceList: (input: AllowanceListQuery) => Promise<GetAllowanceListResp>,

    // 發票通知
    InvoiceNotify: (input: InvoiceNotifyInput) => Promise<InvoiceNotifyOutput>,

    // 查詢折讓作廢明細
    GetAllowanceInvalid: (input: GetAllowanceInvalidInput) => Promise<GetAllowanceInvalidOutput>,

    // 查詢作廢發票
    GetInvalid: (input: GetInvalidInput) => Promise<GetInvalidOutput>,

    // 查詢稅務編號
    GetCompanyNameByTaxID(input: GetCompanyNameByTaxIDInput): Promise<GetCompanyNameByTaxIDOutput>,

    // 查詢發票號碼
    CheckBarcode(input: CheckBarcodeInput): Promise<CheckBarcodeOutput>,

    // 查詢愛心碼
    CheckLoveCode(input: CheckLoveCodeInput): Promise<CheckLoveCodeOutput>,
}
