import { Repository, DataSource } from 'typeorm';
import { TenantsService } from '../tenants/tenants.module';
import { Charge } from '../payments/payments.module';
import { Client } from '../clients/clients.module';
import { MailService } from '../email/email.module';
export declare class AbrasXmlBuilder {
    private readonly NAMESPACE;
    private readonly logger;
    buildRps(params: {
        rpsNumber: number;
        rpsSerie: string;
        rpsType: number;
        competenceDate: string;
        emissionDate?: string;
        providerCnpj: string;
        providerMunicipalInscription: string;
        borrowerDocument: string;
        borrowerName: string;
        borrowerMunicipalInscription?: string;
        borrowerEmail?: string;
        borrowerAddress?: string;
        borrowerAddressNumber?: string;
        borrowerAddressComplement?: string;
        borrowerNeighborhood?: string;
        borrowerIbgeCode?: string;
        borrowerUf?: string;
        borrowerZipCode?: string;
        serviceAmount: number;
        issAliquota: number;
        issRetained: boolean;
        serviceListItem: string;
        discrimination: string;
        serviceCityCode: string;
        issExigibility: number;
        simpleNational: boolean;
        fiscalIncentive: boolean;
    }): string;
    buildCancelRequest(params: {
        nfseNumber: string;
        providerCnpj: string;
        municipalInscription: string;
        cityCode: string;
        cancelCode: number;
        reason?: string;
    }): string;
    buildConsultarPorRps(params: {
        rpsNumber: number;
        rpsSerie: string;
        rpsType: number;
        providerCnpj: string;
        providerMunicipalInscription: string;
    }): string;
    parseNfseResponse(xml: string): {
        nfseNumber?: string;
        chaveAcesso?: string;
        verifyCode?: string;
        rpsNumber?: number;
        nfseUrl?: string;
        errors?: Array<{
            code: string;
            message: string;
        }>;
        acknowledgment?: string;
    };
    signRpsXml(rpsXml: string, certBase64: string, certPass: string, rpsNumber: number): string;
    private escapeXml;
}
export declare class NfseSoapClient {
    private readonly logger;
    private readonly wsdlCache;
    private readonly CABECALHO;
    private cleanUrl;
    private getWsdlInfo;
    sendGerarNfse(endpointUrl: string, xmlBody: string): Promise<string>;
    sendCancelarNfse(endpointUrl: string, xmlBody: string): Promise<string>;
    sendConsultarNfsePorRps(endpointUrl: string, xmlBody: string): Promise<string>;
}
export declare class Invoice {
    id: string;
    tenantId: string;
    chargeId: string;
    contractId: string;
    clientId: string;
    rpsNumber: number;
    rpsSerie: string;
    rpsType: number;
    competenceDate: string;
    nfseNumber: string;
    nfseVerifyCode: string;
    nfseUrl: string;
    nfseXml: string;
    nfseIssuedAt: Date;
    serviceAmount: number;
    issAmount: number;
    issRetained: boolean;
    issAliquota: number;
    netAmount: number;
    serviceListItem: string;
    cnaeCode: string;
    discrimination: string;
    serviceCityCode: string;
    issExigibility: number;
    cancelCode: number;
    cancelReason: string;
    cancelledAt: Date;
    cancelXml: string;
    status: string;
    errorMessage: string;
    retryCount: number;
    consultaFailCount: number;
    queuedAt: Date;
    abrasfProtocol: string;
    emailSentAt: Date;
    createdAt: Date;
    updatedAt: Date;
}
export interface IssueInvoiceParams {
    tenantId: string;
    chargeId?: string;
    contractId?: string;
    clientId: string;
    providerCnpj: string;
    providerMunicipalInscription: string;
    nfseUrl: string;
    simpleNational: boolean;
    fiscalIncentive: boolean;
    nfseCertificate?: string;
    nfseCertificatePass?: string;
    serviceAmount: number;
    issAliquota: number;
    issRetained: boolean;
    serviceListItem: string;
    discrimination: string;
    serviceCityCode: string;
    issExigibility: number;
    competenceDate: string;
    emissionDate?: string;
    borrowerDocument: string;
    borrowerName: string;
    borrowerMunicipalInscription?: string;
    borrowerEmail?: string;
    borrowerAddress?: string;
    borrowerAddressNumber?: string;
    borrowerAddressComplement?: string;
    borrowerNeighborhood?: string;
    borrowerIbgeCode?: string;
    borrowerUf?: string;
    borrowerZipCode?: string;
}
export declare class FiscalService {
    private readonly invoiceRepo;
    private readonly xmlBuilder;
    private readonly soapClient;
    private readonly dataSource;
    private readonly mailService;
    private readonly logger;
    constructor(invoiceRepo: Repository<Invoice>, xmlBuilder: AbrasXmlBuilder, soapClient: NfseSoapClient, dataSource: DataSource, mailService: MailService);
    private nextRpsNumber;
    private validateBorrowerFields;
    issueInvoice(params: IssueInvoiceParams): Promise<Invoice>;
    private resolveIbgeCode;
    processEmission(invoiceId: string, params: IssueInvoiceParams): Promise<void>;
    private autoSendInvoiceEmail;
    cancelInvoice(tenantId: string, invoiceId: string, params: {
        providerCnpj: string;
        municipalInscription: string;
        cityCode: string;
        nfseUrl: string;
        cancelCode: number;
        reason: string;
    }): Promise<Invoice>;
    retryInvoice(tenantId: string, invoiceId: string, params: IssueInvoiceParams, newRpsNumber?: number): Promise<Invoice>;
    consultarInvoice(tenantId: string, invoiceId: string, params: {
        providerCnpj: string;
        providerMunicipalInscription: string;
        nfseUrl: string;
    }): Promise<Invoice>;
    autoRetryStuckInvoices(): Promise<void>;
    syncIssuedInvoices(tenantId: string, params: {
        providerCnpj: string;
        providerMunicipalInscription: string;
        nfseUrl: string;
    }): Promise<{
        total: number;
        updated: number;
        skipped: number;
        errors: number;
    }>;
    getRpsSequence(tenantId: string): Promise<number>;
    setRpsSequence(tenantId: string, value: number): Promise<void>;
    sendInvoiceEmail(tenantId: string, invoiceId: string): Promise<Invoice>;
    findByTenant(tenantId: string, status?: string): Promise<Invoice[]>;
    findOne(tenantId: string, id: string): Promise<Invoice>;
}
export declare class CreateInvoiceDto {
    chargeId: string;
    contractId?: string;
    serviceAmount?: number;
    issAliquota?: number;
    issRetained?: boolean;
    serviceListItem: string;
    discrimination?: string;
    issExigibility?: number;
    competenceDate: string;
}
export declare class RetryInvoiceDto {
    rpsNumber?: number;
}
export declare class CancelInvoiceDto {
    cancelCode: number;
    reason: string;
}
export declare class FiscalController {
    private readonly fiscalService;
    private readonly tenantsService;
    private readonly invoiceRepo;
    private readonly chargeRepo;
    private readonly clientRepo;
    constructor(fiscalService: FiscalService, tenantsService: TenantsService, invoiceRepo: Repository<Invoice>, chargeRepo: Repository<Charge>, clientRepo: Repository<Client>);
    findAll(req: any, status?: string): Promise<Invoice[]>;
    getRpsSequence(req: any): Promise<{
        current: number;
    }>;
    setRpsSequence(req: any, body: {
        value: number;
    }): Promise<{
        current: number;
    }>;
    findOne(req: any, id: string): Promise<Invoice>;
    create(req: any, dto: CreateInvoiceDto): Promise<Invoice>;
    retry(req: any, id: string, dto: RetryInvoiceDto): Promise<Invoice>;
    sendEmail(req: any, id: string): Promise<Invoice>;
    consultar(req: any, id: string): Promise<Invoice>;
    syncIssued(req: any): Promise<{
        total: number;
        updated: number;
        skipped: number;
        errors: number;
    }>;
    cancel(req: any, id: string, dto: CancelInvoiceDto): Promise<Invoice>;
}
export declare class FiscalModule {
}
